Springdoc Swagger UI 不使用 swagger-config

2024-01-19

需要一些有关 springdoc-openapi-ui 的帮助!

我正在使用 springdoc-openapi-ui 来呈现我的 API 模式。这是它的版本详细信息。

Now, i have done some configuration in my spring boot application like below enter image description here

Now, i was expecting that when i hit localhost:15041/swagger-ui.html, it should take me to http://localhost:15041/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config by default this and render my API document but unfortunately it only renders the Petstore. Even if i directly go to http://localhost:15041/swagger-ui.html?configUrl=/v3/api-docs/swagger-config, it doesn't render using the swagger-config. enter image description here

虽然如果我去localhost:15041/v3/api-docs我得到了我的 json API 文档并且localhost:15041/v3/api-docs/swagger-config,我得到了招摇配置。 另外,如果我输入/v3/api-docs在 petstore 页面的 Explore 搜索区域中,它显示了我的 API 文档。

我花了超过 1.5 天的时间来修复它,但它不起作用。如果有人可以提供帮助,我真的很感激。


发现问题了。问题在于 springdoc 库如何使用 swagger-ui。他们写了一些自定义代码 https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/ui/AbstractSwaggerIndexTransformer.java#L193即时修补 swagger-ui jar 返回的 index.html 文件以注入configUrl响应中的查询参数。

现在,当 swagger-ui 从 4.8.1 迁移到 4.9.0 时,它们changed https://github.com/swagger-api/swagger-ui/compare/v4.8.1...v4.9.0#diff-6cbb7b4fa9f894c496c5eb7b048ea9e29a64dd08bc6ba63efba41610f057c0eeindex.html 文件格式破坏了 springdoc 中编写的自定义代码。

为了解决这个问题,目前我们需要降级org.webjars:swagger-ui到 4.8.1,其中 index.html 文件符合 springdoc 的预期,然后它将遵循查询参数中发送的 configUrl。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Springdoc Swagger UI 不使用 swagger-config 的相关文章

随机推荐