drf-yasg: How to change operationId?

1.8k Views Asked by At

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?

1

There are 1 best solutions below

3
On BEST ANSWER

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"})