Skip to content

Rewrite operationId, description and tags from patch.yml using Spectacular

Before

/api/v1/thing/:
  operationId: CustomId
  description: Blah
  tags:
  - elements

After

@extend_schema_view(
    get=extend_schema(
        operation_id='CustomId',
        tags=['elements'],
        description='Blah',
    )
)
class MyEndpoint(RetrieveAPIView):

For endpoints that have a def get(…): method, add the @extend_schema on it directly.

For endpoints that have multiple methods, adding @extend_schema(tags=['elements']) to the class adds tags to every method at once.