常用注解
@Api
Api用在类上,说明该类的作用。可以标记一个Controller类作为swagger文档资源。
@Api(value="/user", description = "Operations about user")
与Controller
注解并列使用,属性配置:
属性名称 | 备注 |
---|---|
value | url的路径值 |
tags | 如果设置这个值,value的值会被覆盖 |
description | 对api资源的描述 |
basePath | 基本路径可以不配置 |
position | 如果配置多个Api想改变显示的顺序位置 |
produces | For example, “application/json, application/xml” |
consumes | For example, “application/json, application/xml” |
protocols | Possible values: http, https, ws, wss. |
authorizations | 高级特性认证时配置 |
hidden | 配置为true 将在文档中隐藏 |
@ApiOperation
ApiOperation
:用在方法上,说明方法的作用,每一个url资源的定时,使用方式:
@ApiOperation(
value = "Find purchase order by ID",
notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
response = Order,
tags = {"Pet Store"}
)
与Controller中的方法并列使用。
@ApiParam
ApiParam请求属性,使用方式:
public ResponseEntity<User> createUser(@RequestBody @ApiParam(value = "Created user object", required = true) User user)