POST 的有效载荷和招摇的 PUT 方法

payload for POST and PUT methods in swagger

我正在使用 yasg 库为我的 api 制作文档.. 但我有一个问题: GET 和 DELETE 方法很好,但是当我想使用 POST 或 PUT 方法时,我无法为它们定义有效负载。 在参数部分它说:没有参数 这是我的代码:

class CreateGroupView(APIView):
    def post(self, request):
        try:
            serializer = GroupSerializer(data=request.data)
            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data, status.HTTP_201_CREATED)
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        except:
            return Response({'data': 'somethings wrong'}, status.HTTP_500_INTERNAL_SERVER_ERROR)

我能做什么?

from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema

type_param = openapi.Parameter('type', in_=openapi.IN_QUERY, description='Type parameter', type=openapi.TYPE_INTEGER)
q_param = openapi.Parameter('q', in_=openapi.IN_QUERY, description='Seach query', type=openapi.TYPE_STRING)

class CreateGroupView(APIView):

    @swagger_auto_schema(
        responses={status.HTTP_201_CREATED: GroupSerializer()},
        operation_description="Some description here...",
        manual_parameters=[type_param, q_param]
    )
    def post(self, request):
        try:
            serializer = GroupSerializer(data=request.data)
            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data, status.HTTP_201_CREATED)
            else:
                return Response(status=status.HTTP_400_BAD_REQUEST)
        except:
            return Response({'data': 'somethings wrong'}, status.HTTP_500_INTERNAL_SERVER_ERROR)