I am trying to create a custom API (not using models), but not showing the definition of the request in the schema (as a result, 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 he appears in swagger, but only part of the answer. How to register message settings? I am also not sure if I am using DRF correctly (I'm a beginner), so any correction will be appreciated.
-
edit: I tried the serializer_class argument suggested by Linovia and did not work, I got:
TypeError: InfoViewSet() received an invalid keyword 'serializer_class'
I tried overriding the get_serializer_class method and did not work:
def get_serializer_class(self):
if self.action == 'some_method':
return InfoSomeMethodSerializer
source
share