Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swagger/drf_yasg: either schema or type are required for Parameter object (not both)

I have the following path:

path('path/<int:object_id>',
     function,
     name='function'),

The way it is, drf_yasg is generating the documentation for object_id as if it as a string:

drf_yasg string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So I decided to manually input the information in the swagger_auto_schema decorator:

@swagger_auto_schema(
    method='PATCH',
    manual_parameters=[
        openapi.Parameter('object_id', openapi.IN_PATH, required=True, description='Object ID'),
        # query parameters
    ],
    # operation_description, responses, etc
)
@api_view(['PATCH'])
@permission_classes([IsAuthenticated])
def function(request, object_id)

However, by doing this, drf_yasg raises the error either schema or type are required for Parameter object (not both)!, and I can’t fix this unless I remove the object_id path parameter form the decorator

Anyway, I’m interested in being able to explicitly descibe my path parameter in the decorator instead of letting drf_yasg doing this by myself

How can I fix this?

>Solution :

you should provide the schema attribute with the desired data type for the object_id parameter.

@swagger_auto_schema(
        method='PATCH',
        manual_parameters=[
            openapi.Parameter('object_id', openapi.IN_PATH, schema=openapi.Schema(type=openapi.TYPE_INTEGER), description='Object ID'),
           
        ],)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading