How to expose Django Rest APIView fields to swagger?

Viewed 307

I have something like this:

class MyCustomView(APIView):
    serializer_class = serializers.MyCustomSerializer

    def post(self, request):
        #my custom logic here, working on multiple tables, etc

But the serialization fields do not show up in swagger or default Django rest HTML view. How can I make it so it does?

Edit

I see it works in browseable API with latest Django Rest, but not in swagger. I'm using drf_yasg. Any ideas how to fix this?

1 Answers

Turns out you can force serializer for swagger like this:

   ...
   @swagger_auto_schema(request_body=SomeSerializer)
   def post():
      pass
   ...
Related