gpt4 book ai didi

swagger - Springdoc OpenAPI ui 不支持 "location"中的上下文路径

转载 作者:行者123 更新时间:2023-12-03 17:00:01 28 4
gpt4 key购买 nike

设置:
我正在使用 Java 库 springdoc-openapi-ui在 1.4.0 版(通过 Maven)中,在一个简单的 spring-boot 项目中没有任何定制。
Swagger 页面是在下面生成的
https://my-url.com/my-context-path/swagger-ui/index.html
以及下面的 api-docs
https://my-url.com/my-context-path/v3/api-docs/
这两个都有效,我可以联系到他们。到现在为止还挺好!
现在的问题:
当简单地导航到 https://my-url.com/my-context-path/swagger-ui.html 时我收到一个 HTTP 状态 302 和一个 location在响应头中设置的属性应该将我从上面重定向到 swagger 页面(我假设)。
但是,location 中的 URL属性缺少上下文路径!它看起来像这样:
https://my-url.com/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
它重定向到一个不存在的页面,我收到 404 错误代码。请注意,configUrl 似乎也缺少上下文路径。
任何想法为什么会发生这种情况以及如何解决?
这个 Github Issue 似乎是同样的问题,但最后说问题已修复:https://github.com/springdoc/springdoc-openapi/issues/37那是针对比我更早的版本。

最佳答案

好的,问题是 springdoc-openapi-ui除非在 spring boot 中定义,否则不知道您的应用程序上下文路径,这对每个人来说都是不可能的。
希望它确实支持非标准标题 X-Forwarded-Prefix可以由您的网关发送。
就我的情况(Kubernetes)而言,只需添加 nginx.ingress.kubernetes.io/x-forwarded-prefix: "true",即可在图表中配置 Ingress。
在您的应用程序配置中,您还需要指定

server:
forward-headers-strategy: framework
使用 Spring 支持处理转发的 header 。
资料来源:
https://github.com/kubernetes/ingress-nginx/issues/3670
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#x-forwarded-prefix-header
https://github.com/springdoc/springdoc-openapi/issues/607

关于swagger - Springdoc OpenAPI ui 不支持 "location"中的上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62153074/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com