1

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?

Javad
  • 2,033
  • 3
  • 13
  • 23

1 Answers1

2

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"})
JPG
  • 82,442
  • 19
  • 127
  • 206
  • I tried adding @swagger_auto_schema(operation_id="Update data entity name") on top of def update(self, request, *args, **kwargs) I still don't see the change. Is there anything else I should do after adding that statement? – Rohit Krishnan Vidyasagar Apr 28 '21 at 08:10
  • instead of `update()` method, use either `put()` or `patch()` method – JPG Apr 28 '21 at 08:49
  • Thank you! That worked. Is there any way I can attach it to the update method? Because we are using create, update, partial_update, list and destroy for our APIs. Sorry for making it more complicated. But thank you so much for the response – Rohit Krishnan Vidyasagar Apr 28 '21 at 09:02