[英]How to exclude show filters for specific endpoint in drf-yasg
我有一些带有filterset_fields
和ordering_fields
属性的 ViewSet。 此外,我在该 ViewSet 中有额外的操作,它用作通过一些过滤获取列表的快捷方式。 我假设使用该额外操作而不处理任何额外的过滤器(或可能是订购)选项。 但默认情况下, drf-yasg 使用filterset_fields
和ordering_fields
为该额外操作生成参数模式。
我如何忽略特定端点的filterset_fields
和ordering_fields
属性?
经过一些研究,我这样做:
from drf_yasg.inspectors import SwaggerAutoSchema
class MySwaggerAutoSchema(SwaggerAutoSchema):
def get_query_parameters(self):
return []
并在swagger_auto_schema
说明符中使用该子类来执行我的额外操作@swagger_auto_schema(auto_schema=MySwaggerAutoSchema)
。
但它看起来很野蛮。 如果有人有更优雅的解决方案 - 请告诉我。
在您的操作装饰器中,将filterset_fields和ordering_fields设置为一个空列表:
@action(detail=False, methods=['GET'], filterset_fields=[], ordering_fields=[], search_fields=[])
您可以进一步 go 并禁用filter_backends :
@action(detail=False, methods=['GET'], filter_backends=[])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.