挥舞着如何将操作返回值链接为授权

时间:2019-10-28 06:30:07

标签: swagger swagger-ui

我正在按照OAS 3.0.2规范来编写。并且想知道是否可以通过操作返回值设置授权值(BearerAuth)。

现在,我需要先调用api / login,然后复制返回令牌并将其粘贴到授权面板。有没有更好的方法可以在操作和安全之间自动链接价值?

我尝试使用Links,但不确定是否对安全性提供支持。 (官方文件中没有提到实现安全性的方法)

paths:
  /login:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                account:
                  type: string
                password:
                  type: string
      responses:
        '200':
          description: data.apiToken
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    description: data
                    properties:
                      apiToken:
                        type: string
                        description: I need this as authorization value
          links:
            ApiToken:
              operationId: apiToken
              parameters:
                apiToken: '$response.body#/data.apiToken'

登录成功,响应正文如下:

{
  "data":{
    "apiToken": "xxxxxx"
  }
}

但是下一步我不知道该怎么做。响应为401,因为令牌未在标头中发送(...我并不感到惊讶)。

  /someapi:
    get:
      summary: This API need auth to get data
      operationId: apiToken
      security:
        - BearerAuth: [apiToken]
      responses:
        '401':
            description: Not work
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

如果我手动复制/粘贴,则可能已成功授权。有什么方法可以解决此问题,或者只是现在不支持此功能?非常感谢。

0 个答案:

没有答案