Search code examples
python-3.xswaggertornado

Tornado swagger Authorization not working


i am using tornado-rest-swagger==1.1.3 for my project wrritten on tornado framework.

Everything works exept the Authorization, main authorization is added and can be locked but authorization on each endpoint is emphy and no header is sent from swagger.

will appreciate any help

# 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

        """

i have added few screenshot to see exactly the issues

when authorized from main authorization, can be seen on screenshot main authorization is locked but on endpoint nothing changed

on second screenshot if i go to endpoint and press the lock there is no authorization available

enter image description here

enter image description here


Solution

  • i have sorted out the issue by inspecting the generated json from swagger directly in html of the page

    automatically the security name was added by it self with the name Authorization

    so by specifying

    security:
        - Authorization: []
    

    it worked, because in my question i was adding different name, so it does not allow to specify a custom name and was generated by itself with Authorization name

    i just had to inspect element on the swagger page and check generated json data