【问题标题】:How to customize API end points on redoc API documentation如何在 redoc API 文档上自定义 API 端点
【发布时间】:2019-03-28 08:20:50
【问题描述】:

我在django==2.0 中使用redoc 来记录一些django API。我注意到默认情况下,redoc 会自动命名端点,如下图左侧所示。很可能我不想使用生成的名称,我想自定义名称。有 redoc 文档经验的人能给你建议吗?

【问题讨论】:

    标签: django django-rest-framework documentation drf-yasg redoc


    【解决方案1】:

    如果你使用drf-yasg,你可以使用swagger_auto_schema装饰器来配置operation_id

    from drf_yasg.utils import swagger_auto_schema
    from django.utils.decorators import method_decorator
    
    @method_decorator(name='get', decorator=swagger_auto_schema(operation_id='List Widgets', operation_description='List all available widgets'))
    class WidgetListView(ListAPIView):
        serializer_class = WidgetSerializer
    
        def get_queryset(self):
            return Widget.objects.all()
    

    【讨论】:

      【解决方案2】:

      这些摘要实际上是从输入 JSON 填充的,可以在源 ["paths"][path][method]["summary"] 的此路径中找到。 您可能需要编辑这些以更改摘要。 如果您不想更改源输入,可以在 REDOC 加载后更改 DOM 元素的文本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-22
        • 2018-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-14
        • 1970-01-01
        • 2020-07-23
        相关资源
        最近更新 更多