首页 > 解决方案 > 是否有任何选项可以为 /swagger-ui 路径添加前缀?开放API

问题描述

你知道如何添加我的应用程序名称 /swagger-ui 作为前缀吗?喜欢

springdoc:
  swagger-ui:
    path: classpath:/META-INF/swagger-ui

但上面的代码根本不起作用。我想访问 localhost:8080/application-service/swagger-ui 而不是 localhost:8080/swagger-ui (这是通过 springdoc.swagger-ui.path=/swagger-ui 解决的

我不想使用:

server:
  servlet:
    context-path: /application-service

因为所有端点都有不同的路线。谢谢

标签: javaspring-bootswaggeropenapispringdoc

解决方案


springdoc:
  swagger-ui:
    path: "application-service"

使用上述方法时,您将能够在以下位置访问 Swagger-UIhttp://localhost:8080/application-service

请注意,即使使用上述属性也会将您重定向到localhost:8080/swagger-ui,但额外的好处是您将拥有不同的 URL 来访问 Swagger-UI。此外,到目前为止,路径中还没有 a /,这意味着您不能有一个 n 级路径来公开 Swagger-UI(这在某种程度上是有道理的,因为 Swagger 是参考文档,应该很容易访问)。


推荐阅读