Append new request example to drf-spectacular schema

Viewed 517

I know the way to add examples for the schema used by drf-spectacular is:

examples=[
            OpenApiExample(
                'Example 1',
                description='longer description',
                value='example'
            ),
        ]

However, instead of creating from scratch the examples, I would like to add a new one to the one that is automatically generated.

Is there a way to do this? Or at least, generate the request body fro the serializer.

Thanks!

1 Answers

drf-spectacular does not generate examples by itself. Uunless you provide OpenApiExample instances. the schema will not contain examples. If you see an example it is because your UI (swagger/redoc) came up with one based on the given types. I assume they stop doing this once you provide an actual example.

I think that makes sense once you indicate that you take care of your examples yourself. In any case it would be a setting in the UI as this has nothing to do with spectacular.

Related