drf-yasg icon indicating copy to clipboard operation
drf-yasg copied to clipboard

Can I provide a custom sample request body?

Open tommus opened this issue 3 years ago • 2 comments

I've been searching for a possibility for a longer while but with no luck.

Is that possible to provide a custom request body example as it is possible for a response body?

I'm not happy with what is being automatically generated based on a serializer definition (and it's field types) and would love to provide my custom request body with an examples more appropriate for given business domain.

Eg. automatically generated request sample for hypothetical authentication method might look like:

{
  "email": "[email protected]",
  "username": "string",
  "password": "pa$$word",
  "first_name": "string",
  "last_name": "string"
}

While I would like to refine it somehow, eg.:

{
  "email": "[email protected]",
  "username": "jon.snow",
  "password": "I_know_nothing",
  "first_name": "Jon",
  "last_name": "Snow"
}

tommus avatar Feb 05 '22 20:02 tommus

This is possible with the swagger_auto_schema method decorator and it's request_body parameter.

MatejMijoski avatar Feb 14 '22 17:02 MatejMijoski

{
    "row_num": 5,
    "current_page": 1,
    "short_field": "reporting_date",
    "current_sort": "DESC"
}

vinaykushwaha588 avatar Feb 02 '23 07:02 vinaykushwaha588