Reputation: 165
im using yasg library for make a doc for my apis.. but i have a problem: GET and DELETE methods are fine but when i want use POST or PUT method i cant define payload for them.. in parameters section it says: No parameters this is my code :
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)
what can i do?
Upvotes: 2
Views: 919
Reputation: 684
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)
Upvotes: 2