aiohttp-swagger icon indicating copy to clipboard operation
aiohttp-swagger copied to clipboard

Support response object and error references in API spec

Open denismakogon opened this issue 8 years ago • 0 comments

Currently only handlers are being analyzed for docstrings. So as part of the docstring it is possible to mention response object and errors using next notation:

      responses:
        200:
          description: List of apps.
          schema:
            $ref: '#/definitions/AppsWrapper'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

It would be nice to map response objects and errors using same swagger syntax. New feature will extend current docstring syntax to include object references:

        """
        ---
        description: Creating project-scoped app
        tags:
        - Apps
        produces:
        - application/json
        parameters:
        - in: body
          name: app
          description: Created project-scoped app
          required: true
          schema:
            type: object
            properties:
              name:
                type: string
        responses:
            "200":
                description: Successful operation
                schema: 
                  $ref: app.App
            "401":
                description: Not authorized
            "409":
                description: App exists
            default:
                description: Unexpected error
                schema:
                 $ref: error.CustomError
        """

where app.App is importable class object reference that would be treated as response object which docstring should also follow specific format as route handlers:

  App:
    type: object
    properties:
      name:
        type: string
        description: "Name of this app."
        readOnly: true
      config:
        type: object
        description: Application configuration
        additionalProperties:
          type: string

denismakogon avatar Dec 12 '16 11:12 denismakogon