drf-yasg
drf-yasg copied to clipboard
Can I provide a custom sample request body?
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"
}
This is possible with the swagger_auto_schema
method decorator and it's request_body
parameter.
{
"row_num": 5,
"current_page": 1,
"short_field": "reporting_date",
"current_sort": "DESC"
}