I have defined a filterset for a DRF ViewSet. drf_yasg correctly renders all the filterset fields as parameters in Swagger for the list endpoint, but not for any other endpoints.
Any idea why?
views.py:
from rest_framework import mixins, viewsets
from django_filters import rest_framework as filters
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from my_app.models import MyModel
from my_app.serializers import MySerializer
class MyFilterSet(filters.FilterSet):
class Meta:
model = MyModel
fields = {
"status",
}
class MyViewSet(
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
viewsets.GenericViewSet,
):
filter_backends = (filters.DjangoFilterBackend, )
filterset_class = MyFilterSet
queryset = MyModel.objects.all()
serializer_class = MySerializer
List is only place where filters are actually used (see here)
There is nothing to filter on create/update/delete since there are no multiple results. Same goes for retrieve, you are fetching an object by id, so filtering single result doesn't make any sense.