DEV Community

Gahyun Son
Gahyun Son

Posted on

1

Customize Schema with @extend_schema_view

The @extend_schema_view decorator doesn't affect the view logic works. It only customizes the API documentation.

You can see the result on /api/docs/.

Image description

You can search the specific data through this function.

The code is

@extend_schema_view(
    list=extend_schema(
        parameters=[
            OpenApiParameter(
                'tags',
                OpenApiTypes.STR,
                description='Comma separated list of IDs to filter',
            ),
            OpenApiParameter(
                'ingredients',
                OpenApiTypes.STR,
                description='Comma separated list of ingredient IDs to filter',
            )
        ]
    )
)
class ...
Enter fullscreen mode Exit fullscreen mode
  • @extend_schema_view: This decorator allows to Extend the auto generate schema that's created by Django Rest Framework Spectacular.
  • list=extend_schema: Extend the schema for the list endpoint.
  • parameters: It can be pass into the request that made to the list API for this view.
  • OpenApiParameter: Parameter class provided DRF spectacular. It allows us to specify the details of a parameter that can be accepted in the API request.
  • First parameter 'tags': Specifying the name of the parameter to filter.
  • OpenApiTypes.STR: The type is a String.
  • description: Help to user.

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay