[Answered ]-Swagger UI examples using drf-spectacular and x-www-form-urlencoded requests

1👍

When it comes to example data, Redoc is very manual in that there is very little automatic generation of examples based on the schema.

AFAIK SwaggerUI does generate a basic example from the schema, however also only for JSON.

If you want to have application/x-www-form-urlencoded examples, you likely need to specify each one manually. Not sure if the juice is worth the squeeze there.

Now to drf-spectacular: OpenApiExample are by default JSON, so if you want a different encoding you need to explicitly set it and also provide a properly encoded value string:

        OpenApiExample(
            'Form-encoded example 1',
            value='YOUR HANDMADE FROM ENCODED DATA STRING',
            media_type='application/x-www-form-urlencoded'
        )
👤Insa

Leave a comment