Drf-yasg: Data object for request_body

Created on 15 Jan 2018  路  11Comments  路  Source: axnsan12/drf-yasg

Is it possible to get rid of "data" node in case when request structure is defined using "request_body" attribute?

screen shot 2018-01-15 at 16 04 04

question

Most helpful comment

I want to request data in form data not in JSON how can I change that in yasg ? by default it is json form I want it to be in form data form @axnsan12
image

All 11 comments

Hello,

I am sorry but I do not really understand your question. The data node is the request body. It is what is sent in the body part of a POST/PUt/PATCH request.

You can get rid of it by not using request_body...

it's ok, if it should be like that (please, close the issue in the case).

PS.
previously when i created swagger docs manually, all the body params are displayed without "data" node in the doc.

...and old rdf swagger doc generators do it the same "no data" way:

screen shot 2018-01-15 at 16 20 09

It seems to me that those are form parameters, not JSON body parameters. You will find that this library generates the same format for form requests (i.e. if your remove json renderers/parsers from the view).

However you will also find that form parameters do not support nesting, and the library your are referencing above would probably incorrectly represent any nested serializers in the request body as a plain string value.

You might find this an interesting read; http://drf-yasg.readthedocs.io/en/stable/custom_spec.html#swagger-spec-overview

Specifically the part about Schema vs Parameter.

Maybe an option to prefer form parameters could be useful for cases where there is no nesting?

@axnsan12
thanks.
it works well when DEFAULT_PARSER_CLASSES is set to FormParser/MultiPartParser.

Glad it worked out for you!

@axnsan12 thread necromancy, but related to your earlier comment. I found a way to make form parameters support nesting. Is there a place to contribute this as a recipe?

I want to request data in form data not in JSON how can I change that in yasg ? by default it is json form I want it to be in form data form @axnsan12
image

https://drf-yasg.readthedocs.io/en/stable/custom_spec.html#swagger-spec-overview

  • request_body
    @swagger_auto_schema(methods=['put', 'post'], request_body=UserSerializer)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnykda picture hnykda  路  3Comments

beaugunderson picture beaugunderson  路  5Comments

agethecoolguy picture agethecoolguy  路  4Comments

Amoki picture Amoki  路  4Comments

therefromhere picture therefromhere  路  3Comments