![](/img/trans.png)
[英]how to set encoding utf-8 in swagger ui for v3/api-docs?
[英]How to change swagger-ui endpoint that generates configuration (/v3/api-docs/swagger-config)
我有一个创建 swagger-ui 端点的服务。 我希望此端点托管在与默认路径不同的路径上(由于 Kubernetes 入口规则)。 这可以通过使用在 springdoc swagger 上轻松实现
springdoc.swagger-ui.path=/myPath/swagger-ui/index.html
但是它正在尝试从默认 url 访问配置
/v3/api-docs/swagger-config
不幸的是,我还需要这个 url 位于特定路径上。 我知道有一个设置可以指定查找 swagger-config 的路径,即:
springdoc.swagger-ui.configUrl=/myPath/v3/api-docs/swagger-config
然而,这不是我要找的。 此设置允许您指定不同的配置源,然后您需要在指定路径上创建资源,否则将找不到资源。 如果我理解正确,默认路径 /v3/api-docs/swagger-config 是某种端点,它会自动创建/生成资源而无需用户创建它。
我正在寻找的是一种在不同路径上访问此自动生成的配置的方法。 会说“如果我访问 /myPath/v3/api-docs/swagger-config 而不是 /v3/api-docs/swagger-config,则生成并返回您的默认配置”。 最好通过 application.properties 中的条目或覆盖应用程序代码中的某些行为
有谁知道如何做到这一点?
Looks like a default configuration URL cannot be configured by the user using available properties - it is strictly hard-coded as the constant - https://github.com/springdoc/springdoc-openapi/blob/e995192d9edd24d2335490bc97d72fea7bcea86a/springdoc-openapi-common/ src/main/java/org/springdoc/core/Constants.java#L41
但是,您可以尝试克服这一点。 我在这里看到两个选项
我想我过去也遇到过类似的问题,它也与 Kubernetes 和我的应用程序前面的代理(API 网关)有关。 I needed to have url like this https://host/api-gw/my-app/swagger-ui.html
and then redirection to https://host/api-gw/my-app/swagger-ui/index.html?configUrl=/api-gw/my-app/v3/api-docs/swagger-config
。 重定向对我来说无法正常工作,因为configUrl
参数中缺少/api-gw/
部分。 The solution to my problem was adding ForwardedHeaderFilter ( https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/filter/ForwardedHeaderFilter.html ) bean to the configuration.
@Configuration
public class ForwardedHeaderFilterConfig {
@Bean
ForwardedHeaderFilter forwardedHeaderFilter() {
return new ForwardedHeaderFilter();
}
}
之后,重定向工作正常,并且configUrl
参数设置为api-gw/my-app/v3/api-docs/swagger-config
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.