DRF 3.6: How to document input parameters in APIView (for automatic generation of doc)?

I am struggling with the automatically generated DRF 3.6 online documentation to provide input parameters to populate the interactive mode.

As a result, I get an empty window for my POST request (for which 3 parameters are actually required):

enter image description here

With Swagger, I could do this directly in a docstring using some YAML. Now, after looking at the DRF documentation, I cannot find a way to do this.

class ActivateCustomerView(APIView): permission_classes = (AllowAny,) def post(self, request): """ View dedicated to activating a pre-recorded customer # Should I add some parameters here? """ serializer = ActivateCustomerSerializer(data=request.data) serializer.is_valid(raise_exception=True) # ... 
+5
source share
2 answers

Got a response from Tom Christie:

serializer_class alone is not enough - the view should implement get_serializer, see https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas.py#L570

So in my case, adding this works well:

 def get_serializer(self): return ActivateCustomerSerializer() 
+2
source

EDIT: I forgot to answer the input parameters. I believe this will be based on a serializer. Have you tried specifying your serializer_class ?

With the built-in DRF documentation generator, you have to put your docstrings at the class level and enable the request method as such:

 class ActivateCustomerView(APIView): """ post: View dedicated to activating a pre-recorded customer # Should I add some parameters here? # if you have a get request get: # your docs for the get handler """ permission_classes = (AllowAny,) def post(self, request): serializer = ActivateCustomerSerializer(data=request.data) serializer.is_valid(raise_exception=True) # ... 
0
source

All Articles