将 springdoc-openapi-ui 依赖项添加到我的 Spring 项目(不是 Spring Boot)后,将生成 OpenAPI V3 文档,并且可以使用默认的 swagger-ui 页面查看:localhost:8080/swagger-ui.html
。因为 springdoc 文档取代了以前的 Swagger 文档,所以我想在相同的 URL 上提供它,localhost:8080/docs/index.html
。根据 springdoc 文档,我的印象是可以通过使用来完成springdoc.swagger-ui.path
选项中的application.properties
:
springdoc.swagger-ui.path=/docs/index.html
但是,我希望能够通过以下方式导航到 API 文档:localhost:8080/docs/index.html
我得到的是 404,localhost:8080/swagger-ui.html
仍然有效,但现在重定向到http://localhost:8080/docs/swagger-ui/index.html?configUrl=/restapi/v3/api-docs/swagger-config
.
我如何配置我的项目,使 swagger-ui 页面通过自定义 URL 可用,即localhost:8080/docs/index.html
而不是默认的localhost:8080/swagger-ui.html
?
Edit
在尝试更多让它工作并查看在线可用信息(例如 springdoc)之后FAQ https://springdoc.org/faq.html#how-to-integrate-open-api-3-with-spring-project-not-spring-boot(在this https://stackoverflow.com/a/68470670/14823855H3AR7B3A7 的回答)我无法让它工作。我决定采用不同的解决方案,它应该具有相同的效果。这springdoc.swagger-ui.path
选项允许指定自定义 URL,但据我了解,转到自定义 URL 会将用户重定向到标准localhost:8080/swagger-ui.html
页。所以现在手动配置重定向:
@RequestMapping("/docs/index.html")
public void apiDocumentation(HttpServletResponse response) throws IOException {
response.sendRedirect("/swagger-ui.html");
}
显然,该库仅与您在评论中提到的 spring-boot 应用程序原生集成。
如果你想使用 spring,这是可能的,但集成细节没有记录,因为它实际上取决于版本/模块和 spring 应用程序的性质。
您可以检查FAQ https://springdoc.org/faq.html#how-to-integrate-open-api-3-with-spring-project-not-spring-boot看看它是否能回答您的问题。
还有一些答案这里就这样 https://stackoverflow.com/questions/59871209/how-to-integrate-open-api-3-with-spring-project-not-spring-boot-using-springdo/59880655#59880655.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)