【发布时间】:2015-11-29 19:28:42
【问题描述】:
如何使用 Swagger 2.0 注释定义基本身份验证并将其显示在 Swagger UI 中。
在我拥有的资源中:
@ApiOperation(value = "Return list of categories", response=Category.class, responseContainer="List", httpMethod="GET", authorizations = {@Authorization(value="basicAuth")})
public Response getCategories();
我看过这里:
https://github.com/swagger-api/swagger-core/wiki/Annotations#authorization-authorizationscope
它说“一旦您声明并配置了您在 API 中支持的授权方案,您就可以使用这些注释来记录资源或特定操作需要哪种授权方案”但我找不到任何东西讨论在哪里声明和配置授权方案。
更新:
我找到了有关如何声明架构的代码,但我仍然没有在 UI 中看到任何有关身份验证架构的信息。我不确定我错过了什么
@SwaggerDefinition
public class MyApiDefinition implements ReaderListener {
public static final String BASIC_AUTH_SCHEME = "basicAuth";
@Override
public void beforeScan(Reader reader, Swagger swagger) {
}
@Override
public void afterScan(Reader reader, Swagger swagger) {
BasicAuthDefinition basicAuthDefinition = new BasicAuthDefinition();
swagger.addSecurityDefinition(BASIC_AUTH_SCHEME, basicAuthDefinition);
}
}
【问题讨论】:
标签: swagger swagger-ui swagger-2.0