我试图在django rest框架中为我的restapi定义AutoSchema(将在django rest framework swagger中显示)。有一个类扩展了APIView。在
该类同时具有“get”和“post”方法。比如:
class Profile(APIView):
permission_classes = (permissions.AllowAny,)
schema = AutoSchema(
manual_fields=[
coreapi.Field("username",
required=True,
location='query',
description='Username of the user'),
]
)
def get(self, request):
return
schema = AutoSchema(
manual_fields=[
coreapi.Field("username",
required=True,
location='form',
description='Username of the user '),
coreapi.Field("bio",
required=True,
location='form',
description='Bio of the user'),
]
)
def post(self, request):
return
问题是get和post请求都需要不同的模式。如何使用AutoSchema实现这一点?在
如果我正确地理解了您的问题所在,您可以在每个方法中定义您的模式,如下所示:
您可以创建自定义架构并重写get_manual_fields方法,根据该方法提供自定义
manual_fields
列表:相关问题 更多 >
编程相关推荐