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?
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)
this is good.this shows required fields in response section..but is there any way to have something like this in parameters section due to test that method with its parameters?
I think
manual parameters
is what you need. I've updated the answer.thats it..thx for help bro...
dude i tested this and it doesnt work..it shows me parameters but when i want fill them i revieved error (invalid_data)...
Update your question. Post your serializer and parameters you need