Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

899
Views
Django - Add Django Rest Swagger schema to DRF tagged functions with `@api_view`

Django - How to add swagger auto schema to DRF tagged functions with @api_view?

I have this function

view.py

@api_view(['POST'])
@swagger_auto_schema(
    request_body=PostSerializer,
    operation_description="Create a post object"
)
def post_create_post(request):

enter image description here But the request body data requirements aren't showing up in Swagger UI. How do you add swagger documentation to endpoints created using @api_view? Also I'd ideally like to add a list of parameters with their types to the swagger schema.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Issue is ordering

@swagger_auto_schema(
    method='post',
    request_body=PostSerializer,
    operation_description="Create a post object"
)
@api_view(['POST'])
def post_create_post(request):

you also need to add an method param to @swagger_auto_schema

over 4 years ago · Santiago Trujillo Report

0

Decorators are applied first for those 'closest' to the function definition. In order to use the @swagger_auto_schema decorator, the @api_view decorator must first be applied.

Hence, the corrected version is:

@swagger_auto_schema(
    request_body=PostSerializer,
    operation_description="Create a post object"
)
@api_view(['POST'])
def post_create_post(request):

Editorial: the other answer states:

you also need to add an method param to @swagger_auto_schema

However, for routes which have only one method, it's not necessary to specify it, as it will be assumed for you, at least in the current version of the drf_yasg library.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!