I have a Java 11 Spring Boot 2.5.1 application.
Swagger works locally via http:
I have added Swagger, which works perfectly on my localhost:
http://localhost:8085/swagger-ui/index.html#/
Swagger does not work remotely via https:
However, when I deploy it to a remote server, I get the following error:
https://mycompany.co/pow-wow/swagger-ui/index.html#/
Error
Failed to load remote configuration.
note: the remote server is accessed via https.
The REST endpoints are accessible on the remote server.
e.g. GET https://mycompany.co/pow-wow/powwow/test-me returns a 200 as expected.
Question
How do I access the Swagger via the remote server?
Code
pom.xml
<!-- Swagger -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
WebSecurityConfig.java
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//http.csrf().disable().authorizeRequests().antMatchers("/powwow/*").hasRole("USER").and().httpBasic();
//http.csrf().disable().authorizeRequests().antMatchers("/*").permitAll().and().httpBasic();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/soapWS/**").permitAll().and()
.authorizeRequests().antMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll().and()
.authorizeRequests().antMatchers("/actuator/**").permitAll()
.anyRequest().authenticated().and()
.httpBasic().and()
.csrf().disable();
}
}
More info:
When looking at the network traffic in the browser when accessing Swagger.
Locally, there is a call to:
http://localhost:8085/v3/api-docs/swagger-config
returns:
{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8085/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}
Remotely, there is a call to:
https://mycompany.co/v3/api-docs/swagger-config
which returns a 302
.
But https://mycompany.co/pow-wow/v3/api-docs/swagger-config
returns:
{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8085/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}
So this suggests the issue is related to the /pow-wow
context path is missing in the call.
You should try and add
springdoc:
swagger-ui:
config-url: /pow-wow/v3/api-docs/swagger-config
url: /v3/api-docs
to your application.properties. In your provided example
https://mycompany.co/pow-wow/v3/api-docs/swagger-config
it shows that you have "/pow-wow/" in your path. Swagger needs to know where to fetch its config.