我一直在尝试没有成功,看看是否可以修改自动生成的Swagger文档。 Django API以允许发送post参数。这是一个示例:
class AllModelSummary(MultipleModelAPIView):
"""
This route will also accept a csv list of filter parameters: ?types=standard,biodbcore,policy.
If this parameter is not specified then it will return all types. ?search=term will search for term
on name, description and doi fields.
"""
filter_backends = (SearchFilter,)
search_fields = ('name', 'description', 'doi')
flat = True
permission_classes = (HasAPIAccess, )
pagination_class = PaginationWithLicence
def get_queryList(self):
types = self.request.query_params.get('types', None)
query_list = ()
if types:
for t in types.split(','):
if t == 'policy':
query_list = query_list + ((Policy.objects.all().order_by('pk'), PolicySerializerMiniList),)
elif t == 'standard':
query_list = query_list + ((Standard.objects.all().order_by('pk'), StandardSerializerMiniList),)
elif t == 'biodbcore':
query_list = query_list + ((BioDBCore.objects.all().order_by('pk'), BioDBCoreSerializerMiniList),)
else:
query_list = (
(Policy.objects.all().order_by('pk'), PolicySerializerMiniList),
(Standard.objects.all().order_by('pk'), StandardSerializerMiniList),
(BioDBCore.objects.all().order_by('pk'), BioDBCoreSerializerMiniList),
)
return query_list
在localhost:8000 / api,我将看到此特定路由的“页面”和“搜索”输入框,但对于“类型”则看不到。有什么方法可以修改此方法以将其他字段添加到Swagger页面?我没有documentation的运气。