Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

901
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda