drf-yasg 如何使用 api 显示示例响应?
drf-yasg How to show sample response with with api?
如何添加 example responses -- (openapi doc) to my swagger doc using drf-yasg 包?
使用drf_yasg.openapi.Response
--(drf-yasg doc) with the help of @swagger_auto_schema(...)
--(drf-yasg doc)装饰器作为
from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
from rest_framework.response import Response
from rest_framework.views import APIView
response_schema_dict = {
"200": openapi.Response(
description="custom 200 description",
examples={
"application/json": {
"200_key1": "200_value_1",
"200_key2": "200_value_2",
}
}
),
"205": openapi.Response(
description="custom 205 description",
examples={
"application/json": {
"205_key1": "205_value_1",
"205_key2": "205_value_2",
}
}
),
}
class MyTestAPIView(APIView):
<b>@swagger_auto_schema(responses=response_schema_dict)</b>
def post(self, request, *args, **kwargs):
return Response({"foo": "bar"})
架构呈现结果
更新
its keep loading and not showing anything
您可能需要点击 “示例值” 文本,如果您正在查找 招摇文档
如何添加 example responses -- (openapi doc) to my swagger doc using drf-yasg 包?
使用drf_yasg.openapi.Response
--(drf-yasg doc) with the help of @swagger_auto_schema(...)
--(drf-yasg doc)装饰器作为
from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
from rest_framework.response import Response
from rest_framework.views import APIView
response_schema_dict = {
"200": openapi.Response(
description="custom 200 description",
examples={
"application/json": {
"200_key1": "200_value_1",
"200_key2": "200_value_2",
}
}
),
"205": openapi.Response(
description="custom 205 description",
examples={
"application/json": {
"205_key1": "205_value_1",
"205_key2": "205_value_2",
}
}
),
}
class MyTestAPIView(APIView):
<b>@swagger_auto_schema(responses=response_schema_dict)</b>
def post(self, request, *args, **kwargs):
return Response({"foo": "bar"})
架构呈现结果
更新
its keep loading and not showing anything
您可能需要点击 “示例值” 文本,如果您正在查找 招摇文档