Swagger 注释以获取授权按钮

Swagger annotation to get authorize button

我正在使用 swagger 来记录我的 java REST API。 X-Auth-Token 应在每个 api 的 header 中发送(一个除外)。 我想要授权的宠物商店 V2 中的按钮。 可以在这里找到:http://petstore.swagger.io/

我了解到它是在swagger生成的jason\yaml文件中定义的。 确切地说,它是在 yaml 中完成的,如下所示:

securityDefinitions:
  petstore_auth:
    type: "oauth2"
    authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
    flow: "implicit"
    scopes:
      write:pets: "modify pets in your account"
      read:pets: "read your pets"
  api_key:
    type: "apiKey"
    name: "api_key"
    in: "header"

我用注释完成的所有 swagger 文档。但是我找不到执行此按钮的注释。 你能帮我找到这个注释吗?

谢谢!

我用过:

@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = {@ApiKeyAuthDefinition(key = "X-Auth-Token",
    in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, name = "X-Auth-Token")}))

然后我在 Swagger-UI 中得到了一个 "Authorized" 按钮。 我检查了它做了什么 - 它调用了一个方法 self.api.clientAuthorizations.add 当`self = window.swaggerUi;'.

所以最后我通过调用 ajax 调用取回令牌并调用此方法来自动授权:

self.api.clientAuthorizations.add('X-Auth-Token',
                  new SwaggerClient.ApiKeyAuthorization("X-Auth-Token", Object.keys(response).map(function (key)
                  { return response[key]}), "header"));

Swagger REST API 操作注释@ApiOperation 还采用以下属性:授权。该属性可以设置为{@Authorization(value = "AuthName")}