Swagger注解-@ApiParam


Swagger注解-@Api
Swagger注解-@ApiOperation
Swagger注解-@ApiImplicitParams 和 @ApiImplicitParam
Swagger注解-@ApiModel 和 @ApiModelProperty
Swagger注解-@ApiResponses 和 @ApiResponse
Swagger注解-@ResponseHeader
Swagger注解-@ApiParam
Swagger注解-@Authorization 和 @AuthorizationScope
Swagger注解-@SwaggerDefinition
Swagger注解-@ExternalDocs
Springboot 集成 Swagger GitHub 地址


使用场景

在 Rest 接口上或 Rest 接口参数前边使用

概述

为 Rest 接口参数添加其它元数据(导入到 yapi 中不会被解析)

属性

属性名称数据类型默认值说明
nameString“”参数名称,参数名称将从 filed/method/parameter 名称中派生,但你可以覆盖它,路径参数必须始终命名为它们所代表的路径部分
valueString“”参数简单描述
defaultValueString“”描述参数默认值
allowableValuesString“”可接收参数值限制,有三种方式,取值列表,取值范围
requiredbooleanfalse是否为必传参数, false:非必传; true:必传
accessString“”参数过滤,请参阅:io.swagger.core.filter.SwaggerSpecFilter
allowMultiplebooleanfalse指定参数是否可以通过多次出现来接收多个值
hiddenbooleanfalse隐藏参数列表中的参数
exampleString“”非请求体(body)类型的单个参数示例
examplesExample@Example(value = @ExampleProperty(mediaType = “”, value = “”))参数示例,仅适用于请求体类型的请求
typeString“”添加覆盖检测到类型的功能
formatString“”添加提供自定义format格式的功能
allowEmptyValuebooleanfalse添加将格式设置为空的功能
readOnlybooleanfalse添加被指定为只读的能力
collectionFormatString“”添加使用 array 类型覆盖 collectionFormat 的功能

Swagger注解-@Api
Swagger注解-@ApiOperation
Swagger注解-@ApiImplicitParams 和 @ApiImplicitParam
Swagger注解-@ApiModel 和 @ApiModelProperty
Swagger注解-@ApiResponses 和 @ApiResponse
Swagger注解-@ResponseHeader
Swagger注解-@ApiParam
Swagger注解-@Authorization 和 @AuthorizationScope
Swagger注解-@SwaggerDefinition
Swagger注解-@ExternalDocs
Springboot 集成 Swagger GitHub 地址


  • 11
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`@ApiParam`、`@Param`、`@ApiImplicitParam`和`@ApiImplicitParameter`注解都是Swagger框架中的注解,用于描述接口参数的信息,但它们有以下不同点: 1. `@ApiParam`注解: 用于描述请求参数中的单个参数信息,可以用在方法的参数和方法的返回值上。通常用于详细说明请求参数的含义、数据类型、是否必填等信息。示例代码如下: ```java @ApiOperation(value = "查询用户信息", notes = "根据用户id查询用户信息") @GetMapping("/{id}") public User getUserById(@ApiParam(name = "id", value = "用户id", required = true) @PathVariable Long id) { return userService.getUserById(id); } ``` 2. `@Param`注解: 用于描述请求参数中的单个参数信息,仅可用于方法的参数上。通常用于简单说明请求参数的含义。示例代码如下: ```java @ApiOperation(value = "添加用户", notes = "添加新用户") @PostMapping("/") public User addUser(@Param("name") String name, @Param("age") Integer age) { return userService.addUser(name, age); } ``` 3. `@ApiImplicitParam`注解: 用于描述请求参数中的单个参数信息,可以用在方法的参数和方法的返回值上。通常用于说明请求参数的含义、数据类型、是否必填等信息。示例代码如下: ```java @ApiOperation(value = "查询用户信息", notes = "根据用户id查询用户信息") @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path") @GetMapping("/{id}") public User getUserById(@PathVariable Long id) { return userService.getUserById(id); } ``` 4. `@ApiImplicitParameter`注解: 用于描述请求参数中的单个参数信息,仅可用于方法的参数上。通常用于说明请求参数的含义、数据类型、是否必填等信息。示例代码如下: ```java @ApiOperation(value = "添加用户", notes = "添加新用户") @PostMapping("/") public User addUser(@ApiImplicitParameter(name = "name", value = "用户名", required = true, dataType = "String", paramType = "query") String name, @ApiImplicitParameter(name = "age", value = "年龄", required = true, dataType = "Integer", paramType = "query") Integer age) { return userService.addUser(name, age); } ``` 总体来说,`@ApiParam`、`@Param`、`@ApiImplicitParam`和`@ApiImplicitParameter`注解都是用于描述接口参数信息的,但适用场景、使用方式略有不同,需要根据具体需求进行选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值