如何在Spring Boot中为swagger ui指定api文档url(开放api v3)?

Cun*_*Kum 9 spring swagger spring-boot openapi

我有一个带有 open-api 3 的 spring boot 应用程序,部署在 Kubernetes 中(spring-boot-starter-parent 2.2.4.RELEASE)。其余端点可通过 ingress 访问,因此 URL 类似于:

https://host/ingress-path
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,一旦应用程序部署到 ingress,api-docs 也可以通过以下方式获得:

https://host/ingress-path/v3/api-docs
Run Code Online (Sandbox Code Playgroud)

当我打开 Swagger UI 时,出现 404,因为 Swagger UI 似乎正在查看 https://host/v3/api-docs... 当我打开时

https://host/ingress-path/swagger-ui/index.html
Run Code Online (Sandbox Code Playgroud)

放入https://host/ingress-path/v3/api-docs“Expore”并运行它,我发现了所有 API。

有人可以建议如何使用一些 spring 属性等为 UI 设置服务器吗?

目前我有这个(从https://host/ingress-path/v3/api-docs.yaml下载)

https://host/ingress-path
Run Code Online (Sandbox Code Playgroud)

该 API 是自动生成的。我想那server必须有url: https://host/ingress-path

似乎我需要具有相对路径的 pathProvider,如下所述:

https://github.com/springdoc/springdoc-openapi/issues/170

但我在 open-api 3 中找不到这样的东西。

你能帮我么?

谢谢!

PS我想我可以通过配置修复它:

springdoc:
  api-docs:
    enabled: true
    path: '/v3/api-docs'
  swagger-ui:
    path: '/swagger-ui'
    config-url: '/ingress-path/v3/api-docs/swagger-config'
    url: '/ingress-path/v3/api-docs'
    doc-expansion: none
    disable-swagger-default-url: true
Run Code Online (Sandbox Code Playgroud)

hac*_*ker 9

谢谢库努库姆

我测试了你的代码并确认它可以工作。

关键部分是spring-ui.url

转发到这里,希望能帮助到其他人

springdoc:
  api-docs:
    enabled: true
    path: '/v3/api-docs'
  swagger-ui:
    path: '/swagger-ui'
    config-url: '/ingress-path/v3/api-docs/swagger-config'
    url: '/ingress-path/v3/api-docs'
    doc-expansion: none
    disable-swagger-default-url: true
Run Code Online (Sandbox Code Playgroud)