Why won't this django-rest-swagger API documentation display/work properly?
I tested this with cigar_example
which is made by django-rest-swagger and in that example they written one custom view which is also not rendering input parameters
Lastly i look into source code and found that django-rest-swagger needs get_serializer_class
to build body parameters
So it worked with the following code:
class isEmailTaken(views.APIView):
permission_classes = [permissions.AllowAny,]
serializer_class = IsEmailTakenSerializer
def get_serializer_class(self):
return self.serializer_class
def post(self, request, *args, **kwargs):
try:
email = request.DATA['email']
except KeyError:
return HttpResponse(
'An email was not given with this request.',
status=status.HTTP_400_BAD_REQUEST,
)
return HttpResponse(
json.dumps(
User.objects.filter(email=email),
content_type="application/json",
status=status.HTTP_200_OK,
)
)
and IsEmailTakenSerializer
:
from rest_framework import serializers
class IsEmailTakenSerializer(serializers.Serializer):
email = serializers.EmailField()