Reputation: 261
I am using drf-yasg
package to integrate Swagger with DRF.
As documentation said I used @swagger_auto_schema
decorator to manually customize auto-generated endpoints. After a lot of tries I still can't figure out why there are no any changes.
So, I tried to add extra query parameter to RetrieveUpdateAPIView
:
class MyCustomView(RetrieveUpdateAPIView):
...
@swagger_auto_schema(
manual_parameters=[openapi.Parameter('test', openapi.IN_QUERY, description="test manual param", type=openapi.TYPE_BOOLEAN)]
)
def retrieve(self, request, *args, **kwargs):
...
After all, nothing seems changed. What exactly I have to do then?
Upvotes: 1
Views: 3498
Reputation: 4279
A query_serializer
parameter was added in 1.18 (https://github.com/axnsan12/drf-yasg/pull/17).
Example:
from rest_framework import serializers
from rest_framework import viewsets
from drf_yasg.utils import swagger_auto_schema
class CustomParametersSerializer(serializers.Serializer):
myparam = serializers.CharField(help_text="My manual querystring parameter")
class MyViewSet(viewsets.ViewSet):
@swagger_auto_schema(query_serializer=CustomParametersSerializer)
def my_route(self, request):
...
Upvotes: 3
Reputation: 35
you have to add swagger_auto_schema
in get method instead of retrieve.
@swagger_auto_schema(
manual_parameters=[openapi.Parameter('test', openapi.IN_QUERY, description="test manual param", type=openapi.TYPE_BOOLEAN)]
)
def get(self, request, *args, **kwargs):
...
Upvotes: 1