[英]Request & Response schema of django-rest-swagger for documenting the API in DRF
I want to document my API using swagger generator tool django-rest-swagger in DRF 我想使用DRF中的swagger生成器工具django-rest-swagger记录我的API
right now I am writing views by inheriting rest_framework.views.APIView
现在我正在通过继承
rest_framework.views.APIView
编写视图
I don't want to write views using viewsets nor serializer. 我不想使用视图集或序列化器编写视图。
Here is the view code sample 这是查看代码示例
from rest_framework.views import APIView
class SomeView(APIView):
'''
get:
some description
post:
some other description
'''
def get(self, request, format=None):
a = self.request.query_params.get('a',None)
b = self.request.query_params.get('b',None)
c = self.request.query_params.get('c',None)
return Response({},status='200')
def post(self, request, format=None):
a = self.request.data.get('a',None)
b = self.request.data.get('b',None)
c = self.request.data.get('c',None)
return Response({},status='201')
Right now I am able to add description for each endpoint. 现在,我能够为每个端点添加描述。
and I want to add request & response schema like below 我想添加如下的请求和响应模式
and I am wondering, how to achieve this without using serializers & viewsets. 我想知道如何在不使用序列化器和视图集的情况下实现这一目标。
In the current version of django-rest-swagger YAML docstrings (as in your example) have been deprecated I believe. 我相信,在django-rest-swagger的当前版本中,YAML文档字符串(如您的示例)已被弃用。 Accordingly, I think you would need to manually define your schema.
因此,我认为您将需要手动定义架构。 The docs include an example of how to do this on the view level:
该文档包含一个如何在视图级别执行此操作的示例:
http://www.django-rest-framework.org/api-guide/schemas/#manualschema http://www.django-rest-framework.org/api-guide/schemas/#manualschema
I know that i'm not answering directly to your question, but i would like to suggest you to try an awesome package that is customizable in every direction: drf-yasg
. 我知道我不会直接回答您的问题,但是我建议您尝试一个可以在各个方向进行自定义的超棒软件包:
drf-yasg
。 You are not obligated to use generic rest_framework stuff nor serializers. 您没有义务使用通用的rest_framework内容或序列化程序。
You can jump directly to Custom schema generation 您可以直接跳至自定义模式生成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.