I am using drf-spectacular to generate an OpenAPI schema for django. As I am not using serializers, I am defining everything in the extend_schema
decorator. Now my question is, if it is possible to manually define a component schema.
Here is an example what my api view looks like:
from rest_framework.decorators import api_view
from drf_spectacular.utils import (extend_schema, OpenApiExample)
from drf_spectacular.types import OpenApiTypes
from rest_framework.response import Response
@extend_schema(
examples=[OpenApiExample(
value=[
{'title': 'A title'},
{'title': 'Another title'},
],
)],
responses={
200: OpenApiTypes.OBJECT
}
)
@api_view(['GET'])
def list_articles(request):
return Response([{'title': 'Test1'}, {'title': 'Test2'}])
and the corresponding component is shown as empty (e.g. in swagger):
Here is the definition in the documentation but I cannot figure out how to achieve it with drf-spectacular.