我们可以在 Springdoc 中用 redoc 替换 swagger-ui

Can we replace swagger-ui with redoc in Springdoc

我正在尝试用 Springdoc 替换手动维护的 swagger 文件。目前,我们使用 ReDoc 来呈现文件,因为它们支持 discriminator

有没有直接的方法来 replace/supersede 嵌入 swagger-uiReDoc

您可以使用

禁用默认的 swagger-ui
springdoc.swagger-ui.enabled=false

请参阅 https://springdoc.org/

中的 "Disabling the swagger-ui" 部分

在那之后,您需要做的就是将 ReDoc 放在您的服务器上,并让它指向通常位于 /context-path/v3/api-docs
的 OpenAPI 描述 请参阅 https://github.com/Redocly/redoc

中的 "Deployment" 部分

在 springdoc 中你可以跳过使用 swagger UI 包并使用:

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-webmvc-core</artifactId>
    </dependency>

相反。然后,您可以在 <redoc /> 组件中指向使用 springdoc(默认为 /v3/api-docs)生成的 swagger 模式的位置。其余的取决于您如何托管 Redoc。在我们的例子中,我们只是向我们的 service/app 添加了一个控制器,它服务于 Redoc 文档页面 (https://github.com/Redocly/redoc#tldr) 中描述的基本 HTML。