有没有办法隐藏端点的一些方法而不是整个端点? (例如显示POST方法但隐藏DELETE方法)
我试图使用AutoSchema
自定义文档
例如,端点就像
router.register(r'audittrial', AuditTrialViewSet, 'AuditTrial')
将定义以下架构
class AuditTrialCustomView(AutoSchema):
@staticmethod
def get_field(name, required, location, schema, description):
return coreapi.Field(
name=name,
required=required,
location=location,
schema=schema,
description=description
)
def get_manual_fields(self, path, method):
extra_fields = []
if method == 'GET':
extra_fields = [
self.get_field("from", False, "query", coreschema.String(), "Date of the start of the Audit Trial"),
....
]
return extra_fields
有没有什么方法可以实现这个目标?
DRF有以下示例 - 看看它是否对您有所帮助。
class CustomAutoSchema(AutoSchema):
def get_link(self, path, method, base_url):
# override view introspection here...
@api_view(['GET'])
@schema(CustomAutoSchema())
def view(request):
return Response({"message": "Hello for today! See you tomorrow!"})
所以api_view
装饰者应该帮助你。它将列表中的方法列表作为参数。