I'm trying to create a custom API (not using models), but its not showing the request definition in the schema (in consequence, not showing it in swagger). My current code is:
views.py
class InfoViewSet(viewsets.ViewSet):@list_route(methods=['POST'])def some_method(self, request):data = JSONParser().parse(request)serializer = GetInfoSerializer(data=data)serializer.is_valid(raise_exception=True)info = get_data_from_elsewhere(serializer.data)return Response(info)
urls.py
router.register(r'^info', InfoViewSet, base_name='info')
serializers.py
class InfoSomeMethodSerializer(serializers.Serializer):list_id = serializers.ListField(child=serializers.IntegerField())password = serializers.CharField()
And it appears in swagger, but just the response part. How can I register the post parameters? I'm also not sure if I'm using DRF correctly (I'm new) so any correction will be appreciated.
--
edit: I tried the serializer_class argument suggested by Linovia and didn't work, I got:
TypeError: InfoViewSet() received an invalid keyword 'serializer_class'
I tried overriding get_serializer_class
method and didn't work either:
def get_serializer_class(self):if self.action == 'some_method':return InfoSomeMethodSerializer