djangodjango-rest-frameworkswagger-2.0drf-yasgredoc

drf-yasg: How to change operationId?


enter image description here

How do I change the name of the request that appears automatically in redoc-ui when using drf-yasg.

For example: In the image, you can see that that the request is named fid_data-entities_update, it is picking this up from the URL.

How do I override/rename it?


Solution

  • You can use the @swagger_auto_schema(...) decorator to override the operationId spec as using operation_id parameter

    from rest_framework import generics
    from rest_framework.response import Response
    from drf_yasg.utils import swagger_auto_schema
    
    
    class OperationIdOverrideAPI(generics.ListAPIView):
    
        @swagger_auto_schema(operation_id="Your awesome name")
        def get(self, request, *args, **kwargs):
            return Response({"message": "ok"})