Arp*_*wal 9 swagger swagger-ui springdoc springdoc-openapi-ui
需要 springdoc-openapi-ui 的一些帮助!
我正在使用 springdoc-openapi-ui 来呈现我的 API 模式。这是它的版本详细信息。
现在,我已经在我的 Spring Boot 应用程序中完成了一些配置,如下所示

现在,我期望当我点击 时localhost:15041/swagger-ui.html,它应该默认带我http://localhost:15041/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config到此并呈现我的 API 文档,但不幸的是它只呈现 Petstore。即使我直接转到http://localhost:15041/swagger-ui.html?configUrl=/v3/api-docs/swagger-config,它也不会使用 swagger-config 进行渲染。

虽然如果我去localhost:15041/v3/api-docs我会得到我的 json API 文档localhost:15041/v3/api-docs/swagger-config,并且我会得到 swagger-config。另外,如果我进入/v3/api-docspetstore 页面的 Explore 搜索区域,它会显示我的 API 文档。
我花了超过 1.5 天的时间来修复它,但它不起作用。如果有人可以提供帮助,我真的很感激。
发现问题了。问题在于 springdoc 库如何使用 swagger-ui。他们编写了一些自定义代码来即时修补 swagger-ui jar 返回的 index.html 文件,以configUrl在响应中注入查询参数。
现在,当 swagger-ui 从 4.8.1 迁移到 4.9.0 时,他们更改了index.html 文件格式,这破坏了用 springdoc 编写的自定义代码。
为了解决这个问题,目前我们需要降级org.webjars:swagger-ui到 4.8.1,其中 index.html 文件符合 springdoc 的预期,然后它将遵循查询参数中发送的 configUrl。
理论上,如果您使用默认的东西,您不必定义任何选项,我的配置如下所示:
springdoc:
swagger-ui:
disable-swagger-default-url: true
urls[0]:
name: 'name'
url: '/v3/api-docs'
Run Code Online (Sandbox Code Playgroud)
有关完整参考和其他有用的设置,请参见此处:https://springdoc.org/#swagger-ui-properties
您还提到,如果您调用 http://localhost:15041/swagger-ui.html?configUrl=/v3/api-docs/swagger-config这是错误的 url ,它就不起作用。正确的网址是您首先提到的网址:http://localhost:15041/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config。但是 localhost:15041/swagger-ui.html 你应该正确路由。
如果您使用 spring-security,您还应该添加以下依赖项: springdoc-openapi-security
如果它不起作用,我想它一定与你的部门有关。
| 归档时间: |
|
| 查看次数: |
27136 次 |
| 最近记录: |