swagger - Springdoc OpenAPI ui 不遵守“位置”中的上下文路径
问题描述
设置:
我正在使用springdoc-openapi-ui
1.4.0 版(通过 Maven)中的 Java 库,而在一个简单的 spring-boot 项目中没有任何自定义。
Swagger 页面在 https://my-url.com/my-context-path/swagger-ui/index.html下生成
以及https://my-url.com/my-context-path/v3/api-docs/下的 api-docs
这两项工作,我可以达到他们。到目前为止,一切都很好!
现在的问题:
当简单地导航到https://my-url.com/my-context-path/swagger-ui.html我得到一个 HTTP 状态 302 和一个location
在响应标头中设置的属性,该属性应该将我重定向到招摇页面从上面(我假设)。
但是,location
属性中的 URL 错过了上下文路径!它看起来像这样:
https ://my-url.com/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
它重定向到一个不存在的页面,我收到 404 错误代码。请注意,configUrl 似乎也缺少上下文路径。
任何想法为什么会发生这种情况以及如何解决?
这个 Github 问题似乎是同样的问题,但最后指出问题已得到解决:https ://github.com/springdoc/springdoc-openapi/issues/37这是我之前的版本。
解决方案
好的,所以问题是springdoc-openapi-ui
不知道您的应用程序上下文路径,除非它是在 Spring Boot 中定义的,这对每个人来说可能都不可能。
X-Forwarded-Prefix
希望它确实支持可以由您的网关发送的非标准标头。
在我的情况下(Kubernetes),可以通过简单地添加 Ingress 在您的图表中配置nginx.ingress.kubernetes.io/x-forwarded-prefix: "true"
在您的应用程序配置中,您还需要指定
server:
forward-headers-strategy: framework
使用 Spring 对处理转发的标头的支持。
资料来源:
推荐阅读
- ocaml - 在 ocamllex 中对字符串进行词法分析
- swift - 带有圆角 UIKit 的 UIImageView 的可点击区域
- c - 为什么这段代码只打印文件的第一行?
- tensorflow - CoreMLTools 转换为 MLModel:reName_Feature 不起作用
- python - Scrapy为什么我的蜘蛛不跟随到下一页?
- java - 如何在 Android 上结束片段上的活动
- r - 拟合非线性方程的参数以匹配实验数据
- java - 在函数调用Android中同步获取位置
- python - Tkinker 按钮功能无法按预期工作
- javascript - 函数不在代码中运行,但在 Chrome 控制台中运行(有时)