Reputation: 23
I have some ViewSet with filterset_fields
and ordering_fields
attributes. Also i have extra action in that ViewSet, that uses as a shortcut to get list with some filtration. I assume to use that extra action without handling any additional filter(or may be ordering) options. But in default way drf-yasg genereates parameters schema for that extra action with filterset_fields
and ordering_fields
.
How i can ignore filterset_fields
and ordering_fields
attributes for specific endpoint?
Upvotes: 2
Views: 2099
Reputation: 188
In your action decorator set filterset_fields and ordering_fields to an empty list:
@action(detail=False, methods=['GET'], filterset_fields=[], ordering_fields=[], search_fields=[])
You can go even further and disable filter_backends:
@action(detail=False, methods=['GET'], filter_backends=[])
Upvotes: 6
Reputation: 23
After some research i'm do that:
from drf_yasg.inspectors import SwaggerAutoSchema
class MySwaggerAutoSchema(SwaggerAutoSchema):
def get_query_parameters(self):
return []
And use that subclass in swagger_auto_schema
decorator for my extra action that way @swagger_auto_schema(auto_schema=MySwaggerAutoSchema)
.
But it looks barbaric. If anyone has a more elegant solution - let me know.
Upvotes: 0