What do these arguments mean in swagger_auto_schema (Django)?
Asked Answered
L

1

8

The project uses a swagger. There is the following code.

@swagger_auto_schema(
        manual_parameters=[
            Parameter('download', IN_QUERY,
                      'Set `Content-Disposition=attachment` to make browser to download file'
                      'instead of showing it.',
                      type='bool'),
            Parameter('share_id', IN_PATH, type='uuid')
        ],
        security=[],
        responses={'400': 'Validation Error (e.g. base64 is wrong)',
                   '200': VideoSerializer}
    )

Please explain what each argument is responsible for. I read the documentation, but understood little ... Particularly interested in '200': VideoSerializer

Leishaleishmania answered 8/10, 2019 at 11:56 Comment(0)
S
13

responses

The responses argument is a dictionary of possible responses that this endpoint can return.

400 and 200 are HTTP response codes, Bad Request and OK respectively.

In this case, this means that this endpoint can generate two types of responses:

  • Bad request which will also return (as described) a Validation Error which means that something in the request was incorrect, which means it could not be handled correctly.

  • OK, which means the request is correct, and everything was handled correctly. VideoSerializer means that a response will be given with accordance to the structure of the VideoSerializer, which defines a collection of fields.


The other two arguments:

manual_parameters

This a custom list of parameters that can be added to the request to customize the response. In this case, two parameters are defined:

  • download : A query parameter of type bool. Query parameters are passed like this : `example.com?query_parameter=true
  • share_id, a path parameter of type 'uuid'. Path parameters are passed like this : example.com/path_parameter

security A list of security schemes that the request must adhere to. Used for instance for Basic authentication.

Sinistral answered 8/10, 2019 at 13:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.