Ivan Yakushenko
Ivan Yakushenko

Reputation: 169

Why isn't the request body displayed in Flask Swagger UI?

I am trying to write API documentation using the flasgger library:

@bp.route('/long_to_short', methods=['POST'])
def long_to_short():
    '''Create a short URL
    ---
    tags:
        - long_to_short
    requestBody:
        content:
            application/json:
                schema:
                    type: array
                    items:
                        long_url: https://google.com
        required: true

    '''

But the UI does not display information about the request body: swagger ui How do I write the documentation correctly so that it displays correctly?

Upvotes: 0

Views: 1979

Answers (2)

Ivan Yakushenko
Ivan Yakushenko

Reputation: 169

Here's the valid markup:

@bp.route('/long_to_short', methods=['POST'])
def long_to_short():
    '''Create a short URL
    ---
    tags:
        - long_to_short
    requestBody:
        content:
            application/json:
                schema:
                    $ref: '#definitions/Shortener'
    definitions:
        Shortener:
            type: object
            required:
                - long_to_short
            properties:
                long_to_short:
                    type: string
                    example: https://google.com
    '''

Upvotes: 1

Conor
Conor

Reputation: 23

Hopefully this will work for you

   tags:
   - long_to_short
   consumes:
   - "application/json"
   parameters:
   - in: "body"
     name: "body"
     required: true
     schema:
       type: "array"
       items:
        type: "object"
        properties:
         long_url:
         type: "string"
         example: "https://google.com"

Upvotes: 0

Related Questions