How to change example format value of datefield in drf yasg (swagger)

1k Views Asked by At

Hello im using drf yasg library to implement swagger in my django based app. I have changed the date format in settings.py file to look like this:

REST_FRAMEWORK = {
    "DATE_INPUT_FORMATS": ["%d-%m-%Y"],
}

Now when I try to test my endpoint in the swagger then I get example of date field in wrong format:

{
  "birth_date": "2021-04-27",
}

And when I try to execute the request I receive the error:

{
  "birth_date": [
    "Date has wrong format. Use one of these formats instead: DD-MM-YYYY."
  ]
}

What is expected to receive but it's annoying to change the example date each time I want to use it. Any tips how to achieve the same format in the swagger example?

0

There are 0 best solutions below