我们正在nginx
代理后面运行服务,以便:
http://service-post:8080/swagger-ui.html
被路由到公共地址 https://host.com/services/post/swagger-ui.html
或从另一种方式定义:
当nginx在上收到请求时https://host.com/services/post/swagger-ui.html
,它会删除/services/post/
前缀并将请求传递到路径上的post
服务/swagger-ui.html
。
在设置任何东西之前(使用默认的SpringDoc配置),我可以正确地看到swagger文档http://service-post:8080/swagger-ui.html
。
要在host.com上设置公共地址的路径,我正在使用:
springdoc.api-docs.path: /services/post/api-docs
springdoc.swagger-ui.path: /services/post/swagger-ui.html
springdoc.swagger-ui.configUrl: /services/post/v3/api-docs/swagger-config
但是,似乎这完全制止了它:
/swagger-ui.html
,/api-docs
并/v3/api-docs/swagger-config
返回404
两者的service-post:8080/*
和https://host.com/services/post/*
似乎唯一起作用的是显示petstore文档的https://host.com/services/post/swagger-ui/index.html。
我们不使用Spring Boot,而只是使用5.3.1版的Spring MVC 。
那么,如何设置以保留对原始路径(例如/api-docs
)的处理,但是在前缀路径(/services/post/api-docs
)上执行查找呢?
最后,我完全忽略了默认重定向:
swagger-ui.html
->`swagger-ui / index.html?url = / v3 / api-docs并实现了我自己的:
docs
-> swagger-ui/index.html?url=MY_PREFIX/v3/api-docs
这样,我无需进行任何更改,所有设置都可以使用默认设置。
在springdoc-openapi中(也许还有swagger),您可以使用属性更改application.properties中的url,
springdoc.swagger-ui.url
以便访问swagger-ui.html会将您重定向到正确的url。