'How to use swagger_auto_schema in a class based view with no serializer_class and how to add custom authentication permission to it?

I have a class based view as:

class ClassBasedView(GenericAPIView):
    
    @swagger_auto_schema(responses={201: 'Created'})
    @authorize(myCustomPermission)
    def post(self, *args, **kwargs) -> Response:
        // code.....
        return Response(status=HTTPStatus.CREATED)

First:

The use of swagger_auto_schema without any serializer is throwing error as: AssertionError: DetailView should either include a serializer_class attribute, or override the get_serializer_class() method.

And I don't want to use serializer for this endpoint as I don't need that. But the swagger_auto_schema keeps on throwing this error. I want to know whether there is any way to avoid the use of serializer and get the swagger documentation of this endpoint.

Second:

I want to add my custom authorisation permission of this endpoint in the doc. There is a security field in swagger_auto_schema, but don't know how to make it to use for my custom permission class ie myCustomPermission

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source