使用swagger定义API文档

mac2022-06-30  52

@ApiOperation不是spring自带的注解是swagger里的 com.wordnik.swagger.annotations.ApiOperation;

@ApiOperation和@ApiParam为添加的API相关注解,个参数说明如下: @ApiOperation(value = “接口说明”, httpMethod = “接口请求方式”, response = “接口返回参数类型”, notes = “接口发布说明”)   其他参数可参考源码; @ApiParam(required = “是否必须参数”, name = “参数名称”, value = “参数具体描述”)

 

@ApiImplicitParam 用于方法 表示单独的请求参数

 

 

@ApiImplicitParams() 用于方法,包含多个 @ApiImplicitParam name–参数ming value–参数说明 dataType–数据类型 paramType–参数类型 example–举例说明

参考 https://www.2cto.com/kf/201710/692105.html

 

@ApiResponses

用于表示一组响应

@ApiResponse

用在@ApiResponses中,一般用于表达一个错误的响应信息code:数字,例如400message:信息,例如”请求参数没填好”response:抛出异常的类

 

 

实际项目中非常需要写文档,提高Java服务端和Web前端以及移动端的对接效率。

Swagger是当前最好用的Restful API文档生成的开源项目,通过swagger-spring项目

实现了与SpingMVC框架的无缝集成功能,方便生成spring restful风格的接口文档,

同时swagger-ui还可以测试spring restful风格的接口功能。

 

参考:https://blog.csdn.net/fansunion/article/details/51923720

详细文档参考:https://github.com/swagger-api/swagger-core/wiki/Annotations

转载于:https://www.cnblogs.com/xiaoQ0725/p/8855120.html

最新回复(0)