[英]How to exclude show filters for specific endpoint in drf-yasg
I have some ViewSet with filterset_fields
and ordering_fields
attributes.我有一些带有filterset_fields
和ordering_fields
属性的 ViewSet。 Also i have extra action in that ViewSet, that uses as a shortcut to get list with some filtration.此外,我在该 ViewSet 中有额外的操作,它用作通过一些过滤获取列表的快捷方式。 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
.但默认情况下, drf-yasg 使用filterset_fields
和ordering_fields
为该额外操作生成参数模式。
How i can ignore filterset_fields
and ordering_fields
attributes for specific endpoint?我如何忽略特定端点的filterset_fields
和ordering_fields
属性?
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
decarator for my extra action that way @swagger_auto_schema(auto_schema=MySwaggerAutoSchema)
.并在swagger_auto_schema
说明符中使用该子类来执行我的额外操作@swagger_auto_schema(auto_schema=MySwaggerAutoSchema)
。
But it looks barbaric.但它看起来很野蛮。 If anyone has a more elegant solution - let me know.如果有人有更优雅的解决方案 - 请告诉我。
In your action decorator set filterset_fields and ordering_fields to an empty list:在您的操作装饰器中,将filterset_fields和ordering_fields设置为一个空列表:
@action(detail=False, methods=['GET'], filterset_fields=[], ordering_fields=[], search_fields=[])
You can go even further and disable filter_backends :您可以进一步 go 并禁用filter_backends :
@action(detail=False, methods=['GET'], filter_backends=[])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.