@ApiImplicitParams http://docs.swagger.io/swagger-core/current/apidocs/io/swagger/annotations/ApiImplicitParams.html and @ApiImplicitParam http://docs.swagger.io/swagger-core/current/apidocs/io/swagger/annotations/ApiImplicitParam.html应该做的伎俩:
@GET
@Produces("application/json")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Authorization token",
required = true, dataType = "string", paramType = "header") })
public String getUser(@PathParam("username") String userName) {
...
}
来自文档 https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#apiimplicitparam-apiimplicitparams:
您可能希望手动描述操作参数。这可能有多种原因,例如:
- 使用不使用 JAX-RS 注释的 Servlet。
- 想要隐藏定义的参数并用完全不同的定义覆盖它。
- 描述在到达 JAX-RS 实现之前由过滤器或其他资源使用的参数。
Swagger UI 将更新,以便您可以从那里发送令牌。无需对 HTML 进行任何更改。
Note: A while ago, when documenting a REST API with Swagger, I realized that just adding @ApiImplicitParam http://docs.swagger.io/swagger-core/current/apidocs/io/swagger/annotations/ApiImplicitParam.html is not enough (even if you have only one parameter). Anyway, you must add @ApiImplicitParams http://docs.swagger.io/swagger-core/current/apidocs/io/swagger/annotations/ApiImplicitParams.html too.