pythonflaskswaggerconnexion

Swagger adding custom attributes to parameter definition


We have a python web server app based on connexion and Flask libraries. For audit purposes we print every request, including request body, to the logs. Those logs are much more extensive than what Flask prints by default.

However, there are parameters like passwords or keys that I don't want to print their values to the logs.

I want to add custom attribute to several parameters' definition in swagger.yml so on web app start up I will get parameters definitions from connexion and save all the parameters that have this custom attribute, so later on I will hide values of those parameters in the logs.

My desired definition:

    paths:
      /demo_add_user:
        post:
          summary: "add user"
          operationId: api.api.demo_add_user
          parameters:
            - name: "new_user"
              in: body
              required: true
              description: "Use to add"
              schema:
                $ref: "#/definitions/NewUser"
            - name: "password"
              in: body
              description: "user password"
              required: false
              type: string
              x-hidden: true
          responses:

Obviously, I would like connexion to ignore this attribute since this is specific to our implementation. Any way to add custom attribute like x-hidden to parameter definition?


Solution

  • The solution is to use OpenApi extensions by adding x-attr like attribute.

    The details are in next link: https://swagger.io/specification/#specificationExtensions