drf-yasg:如何更改 operationId?

问题描述

enter image description here

如何更改使用 drf-yasg 时自动出现在 redoc-ui 中的请求名称

例如:在图片中,您可以看到请求名为 fid_data-entities_update,它是从 URL 中提取的。

如何覆盖/重命名它?

解决方法

您可以像使用 operation_id 参数一样使用 @swagger_auto_schema(...) 装饰器覆盖 operationId 规范

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