在您的views.py中添加以下内容
进口
from rest_framework.schemas import AutoSchema
from rest_framework.compat import coreapi
#creating custom class
class CustomSampleSchema(AutoSchema):
def __init__(self):
super(CustomSampleSchema, self).__init__()
def get_manual_fields(self, path, method):
extra_fields = [
coreapi.Field('field1', required=True, location='form', description='', type='', example=''),
coreapi.Field('field2', required=False, location='form', description='', type='', example=''),
coreapi.Field('field3', required=False, location='form', description='', type='', example='')
]
manual_fields = super().get_manual_fields(path, method)
return manual_fields + extra_fields
这是您正在为其编写 swagger doc 的功能。
@api_view(['post'])
@schema(CustomSampleSchema())
@csrf_exempt
def func_name(request, param):
"""
Your function definition below
"""
示例 json 输入
{"name": "['name1', ]",
"places": "['place1', 'place2']",
"key":"12345"}