When I add swagger/openapi view support (with help of drf-yasg for example) I get undesirable/incorrect specification for writable methods (POST, PUT, PATCH), they correspond to read_serializer_class instead of to write_serializer_class.
What I Did
from drf_rw_serializers import viewsets
class MyViewSet(viewsets.ModelViewSet):
read_serializer_class = serializers.ReadSerializer
write_serializer_class = serializers.WriteSerializer
To fix that problem I suggest to add something along the following lines:
def get_serializer_class(self):
if self.request.method in ['GET']:
return self.get_read_serializer_class()
return self.get_write_serializer_class()
Hopefully I provided sufficient amount of information.
Description
When I add swagger/openapi view support (with help of drf-yasg for example) I get undesirable/incorrect specification for writable methods (POST, PUT, PATCH), they correspond to
read_serializer_class
instead of towrite_serializer_class
.What I Did
To fix that problem I suggest to add something along the following lines:
Hopefully I provided sufficient amount of information.
Thank you for your efforts.