0

我正在使用 tornado-rest-swagger==1.1.3 来编写我在 tornado 框架上编写的项目。

除了授权之外,一切正常,添加了主要授权并且可以锁定,但每个端点上的授权都是 emphy 并且没有从 swagger 发送标头。

将不胜感激任何帮助

# swagger setup

from tornado_swagger.setup import setup_swagger

if __name__ == '__main__':

    setup_swagger(
        routes,
        swagger_url="/api/affiliate",
        description="",
        api_version="1.0.0",
        title="Affiliate API",
    )


@components.security_schemes.register
class Authorization(object):
    """
    ---
    type: apiKey
    in: header
    name: Authorization
    """

handler

class Countries(AffiliateBaseHandler, ABC):

    def initialize(self, *args, **kwargs):
        super(Countries, self).initialize(*args, **kwargs)

    @authenticated()
    @coroutine
    def get(self):
        """
        ---
        security:
        - ApiKeyAuth: []
        tags:
          - Helpers
        summary: Countries list
        operationId: countries_list
        parameters:
            - in: header
              name: Authorization
              required: true
              schema:
                type: string
        responses:
            '200':
              content:
                application/json:
                  schema:
                    $ref: '#/components/schemas/CountryResponse'
            UnauthorizedError:
                description: Access token is missing or invalid

        """

我添加了一些屏幕截图以查看确切的问题

当从主授权授权时,可以在屏幕截图上看到主授权被锁定但在端点上没有任何改变

在第二个屏幕截图上,如果我转到端点并按下锁,则没有可用的授权

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

我已经通过直接在页面的 html 中检查从 swagger 生成的 json 来解决这个问题

安全名称是由它自己自动添加的,名称为Authorization

所以通过指定

security:
    - Authorization: []

它起作用了,因为在我的问题中我添加了不同的名称,所以它不允许指定自定义名称,并且是使用授权名称自行生成的

我只需要检查 swagger 页面上的元素并检查生成的 json 数据

于 2021-08-16T15:11:26.517 回答