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:
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?
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'),
],)