Different serializers for request/response in create()

139 views
Skip to first unread message

Adam Fletcher

unread,
Aug 22, 2021, 7:40:55 PM8/22/21
to django-res...@googlegroups.com
Hi DRFers,

I'd like to let the schema generator know I have one serializer for my request and one for my response in my create() method. How do I do this? 

-Adam

Adam Fletcher

unread,
Aug 22, 2021, 8:41:30 PM8/22/21
to django-res...@googlegroups.com
I've tried:

class CustomSchema(AutoSchema):
    def get_request_serializer(self, path, method):
        return ImportJsonSerializer()

    def get_response_serializer(self, path, method):
        return IngestionResultSerializer()

class ImportJsonViewSet(viewsets.GenericViewSet):
    permission_classes = (permissions.IsAuthenticated,)
    schema = CustomSchema()
    serializer_class = ImportJsonSerializer()
....

But my OpenAPI schema doesn't reflect the CustomSchema - for example, the request & response in my create() method are both set to the value of serializer_class

Now, I could get rid of the serializer class - or override the method get_serializer_class(), but that's not what AutoSchema is using to determine the schema.

Thoughts?


Adam Fletcher

unread,
Aug 23, 2021, 1:13:13 PM8/23/21
to django-res...@googlegroups.com
Ah, I'm dumb - I was on an older version of DRF that didn't have the `get_response|get_request` changes in. Fixed!

-Adam

Reply all
Reply to author
Forward
0 new messages