Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do these arguments mean in swagger_auto_schema (Django)?

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

like image 328
unknown Avatar asked Oct 08 '19 11:10

unknown


1 Answers

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.

like image 55
Nico Griffioen Avatar answered Oct 19 '22 14:10

Nico Griffioen