Django-rest-framework: No way to add input parameters to Automatic doc generation? (for APIView)

Created on 4 May 2017  路  5Comments  路  Source: encode/django-rest-framework

As explained in this Stack Overflow post, the current documentation does not explain how to specify input parameters for non generic API Views, in order to be provided in the new DRF 3.6 doc.

I don't know if it's possible actually.

Documentation

Most helpful comment

Actually I mis-spoke. serializer_class by itself isn't enough - the view needs to implement get_serializer, see: https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas.py#L570

Ie. the docs are only designed to be able to introspect GenericAPIView subclasses.

All 5 comments

You'll need to put a serializer_class on the view if you want the API documentation to be able to introspect that.

We could do a better job of documenting that.

In my case, even with the serializer_class provided, no input parameter is detected in the doc.
Is it a bug or am I missing something?
Here is the code:

views.py

class ActivateCustomerView(APIView):
    """
    put: View dedicated to activating a pre-recorded customer
    """

    permission_classes = (AllowAny,)
    serializer_class = ActivateCustomerSerializer

    def put(self, request):
        serializer = ActivateCustomerSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        return Response(status=HTTP_200_OK)

serializers.py

class ActivateCustomerSerializer(serializers.Serializer):
    email = EmailField()
    signup_code = CharField()
    raw_password = CharField()

    def validate(self, data):
        # some stuff..
        return data

Any idea @tomchristie ?

Actually I mis-spoke. serializer_class by itself isn't enough - the view needs to implement get_serializer, see: https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas.py#L570

Ie. the docs are only designed to be able to introspect GenericAPIView subclasses.

Was this page helpful?
0 / 5 - 0 ratings