Like my title says, I recently upgraded from 2.7 to 2.8, now when I go to localhost:8080/swagger-ui.html I get this message: Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. However I never got this message when using 2.7, so whats the issue?
here is my pom:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
My Swagger Config:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
}
````
My Web Config:
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/", "swagger-ui.html");
}
}
```
UPDATE:
So I took a peak a the console and noticed it was trying to get the resources from http://localhost:8080/null/swagger-resources so I add this line to my swagger config
.pathMapping("/")
And now when I look at the console log for localhost:8080/swagger-ui.html I see this
http://localhost:8080/swagger-resources 401 ()
http://localhost:8080/swagger-resources/configuration 401 ()
http://localhost:8080/swagger-resources/configuration/security 401 ()
And I still see this message : Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. So my issues still remains the same
I鈥檓 experiencing the same issue. What I noticed in my case is the fetch api is not sending any cookies when trying to retrieve the line below. I see a http 401 since the auth cookie is not sent.
const configUIResponse = await fetch(baseUrl + "/swagger-resources/configuration/ui");
Seems like spring security is interfering with your requests. Have you seen the this guide?
I have solved my issues my added this to my security class
@Override
protected void extendedConfigure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests().antMatchers("/swagger-resources/**").permitAll().anyRequest().fullyAuthenticated();
httpSecurity.httpBasic();
}
Most helpful comment
I have solved my issues my added this to my security class