如何向 Swagger 中的所有路径添加 401 响应 [英] How can I add a 401 response to all paths in Swagger

查看:93
本文介绍了如何向 Swagger 中的所有路径添加 401 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想在 Swagger 中记录的 rest api.对于所有请求,API 都可以使用 401 进行响应.

I have a rest api that I want to document in Swagger. On all requests the API can respond with a 401.

因此,不要为每条路径一遍又一遍地定义 401(不是那么 DRY).我想定义所有路径都可以返回 401.

So instead of defining the 401 again again and again for each path (not so DRY). I want to define that all paths can return a 401.

这可能吗?

推荐答案

据我所知,这是不可能的.您需要使用 @ApiResponse 注释每个 API 端点.类级别唯一可用的注释是 @Api 和 @ApiModel .详情请参考此链接-

As far as i know, this is not possible. You will need to annotate each API endpoint with @ApiResponse. The only annotations available at the class level are @Api and @ApiModel . For details, please refer to this link -

http://docs.swagger.io/swagger-core/v1.5.0/apidocs/io/swagger/annotations/ApiModel.html

这篇关于如何向 Swagger 中的所有路径添加 401 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆