JPG*_*JPG 6

使用drf_yasg.openapi.Response- (DRF-yasg DOC)的帮助下@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):

    @swagger_auto_schema(responses=response_schema_dict)
    def post(self, request, *args, **kwargs):
        return Response({"foo": "bar"})
Run Code Online (Sandbox Code Playgroud)

架构呈现结果

架构呈现结果

更新

它继续加载并且不显示任何内容

如果您正在查看Swagger文档,则可能需要单击“示例值”文本

加载微调器