Reputation: 6126
Here's my pom.xml
:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
I am using version 1.5.3.RELEASE
of Spring Boot. Here's my swagger config file:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swagger() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Here's my WebSecurityConfig.java
:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**");
}
When I do a get from the endpoint http://localhost:8080/v2/api-docs
I get my JSON back:
{
"swagger": "2.0",
"info": {
"description": "Api Documentation",
"version": "1.0",
"title": "Api Documentation",
"termsOfService": "urn:tos",
"contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
},
"host": "localhost:8080",
"basePath": "/",
//ETC
}
But when I try to access the UI at localhost:8080/swagger-ui.html
I get a blank page that looks like this:
If I click on the page, I get promoted with this
What am I doing wrong? Is this some sort of spring security issue?
Upvotes: 5
Views: 15120
Reputation: 1416
if You use Version - V3 || io.springfox >= 3.0.0
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Java code
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("Your Controller package name"))
.paths(PathSelectors.any()).build();
}
}
V3 browser URL -> http://localhost:8080/swagger-ui/#/
Run (Must need) : Mvn clean
Upvotes: 2
Reputation: 119
change the swagger version to 2.9.2 it will work.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
Upvotes: -1
Reputation: 5487
Its very likely spring-security is not allowing/preventing your endpoints to be discovered. Try changing your ant matchers to the following and see if that helps. The security/ui configuration endpoints were incorrect.
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/v2/api-docs",
"/swagger-resources/configuration/ui",
"/swagger-resources",
"/swagger-resources/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
Upvotes: 0