Reputation: 843
I have a service that creates a swagger-ui endpoint. I want this endpoint to be hosted on a path different than default (due to Kubernetes ingress rules). This is easily achieved on springdoc swagger by using
springdoc.swagger-ui.path=/myPath/swagger-ui/index.html
However it is trying to access configuration from a default url
/v3/api-docs/swagger-config
Unfortunately I also need this url to be on specific path. I know there is a setting to specify a path to look for swagger-config, namely:
springdoc.swagger-ui.configUrl=/myPath/v3/api-docs/swagger-config
However this isn't what I'm looking for. This setting lets you specify a different source of configuration and then you need to create a resource on specified path or the resource will not be found. If I understand correctly, the default path /v3/api-docs/swagger-config is some kind of endpoint that is automatically creates/generates the resource without requiring user to create it.
What I am looking for is a way to have access to this automatically generated config on a different path. Something that would say "Generate and return me your default configuration if I access /myPath/v3/api-docs/swagger-config instead of /v3/api-docs/swagger-config". Preferably by entry in application.properties or overriding some behavior in application code
Does anyone know how this can be achieved?
Upvotes: 6
Views: 10963
Reputation: 1726
try springdoc.api-docs.path=/myPath/v3/api-docs/swagger-config
https://springdoc.org/properties.html#properties
Upvotes: 5
Reputation: 133
I suppose I had a similar problem in the past and it was also related to Kubernetes and a proxy (API Gateway), which is in front of my application. 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
. The redirection didn't work properly for me, because the /api-gw/
part was missing in configUrl
parameter. 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();
}
}
After that, redirection worked fine and the configUrl
parameter was set to api-gw/my-app/v3/api-docs/swagger-config
.
Upvotes: 2