question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

api_docs shows content but swagger-ui (2.6.1) is empty

See original GitHub issue

Hi this is a question on configuration. I was reading for hours today but did not get my mistake.

Symptom:

http://localhost:8080/sabi/api/v2/api-docs/ shows me that the annotations have been scanned and assembled. I get a detailed json containing my content.

However when calling the swagger-ui http://localhost:8080/sabi/swagger-ui.html The ui renders, but I can see non of my API. Even by pasting the api-docs url from above and pressing enter did not lead to any result.

Here’s my setup:

Im using:

           <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.6.1</version>
                <scope>compile</scope>
            </dependency>

            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.6.1</version>
                <scope>compile</scope>
            </dependency>

with spring-webmvc (4.2.1-RELEASE) and using xml-free annotation based config:

@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages = "de.bluewhale.sabi")
@PropertySource("classpath:server.properties")
public class AppConfig {

    @Autowired
    Environment env;

    @Bean
    public EncryptionService encryptionService() {
        return new EncryptionService(env.getProperty("accessToken.salt"), env.getProperty("accessToken.password"));
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer properties() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

and


@Configuration
public class ApiDocumentationConfiguration {

    @Bean
    public Docket documentation() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    // .paths(regex("/api/*"))
                    .build()
                .pathMapping("/api")
                .apiInfo(metadata());
    }

    private ApiInfo metadata() {
        return new ApiInfoBuilder()
                .title("sabi's REST API documentation")
                .description("see https://github.com/StefanSchubert/sabi")
                .version("1.0")
                .license("MIT Licence (MIT)")
                .licenseUrl("https://github.com/StefanSchubert/sabi/blob/master/LICENSE")
                .contact("Stefan.Schubert@bluewhale.de")
                .build();
    }
}

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:42 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
StefanSchubertcommented, Jun 16, 2017

Finally it’s working for me too. I needed to throw “api” as pathMapping of the docket config:

    @Bean
    public Docket documentation() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    // .paths(regex("/api/*"))
                    .build()
                .pathMapping("/")
                .apiInfo(metadata());
    }

Also I have api as part of the base path of my controllers:

@RestController
@RequestMapping(value = "api/user")
public class AuthenticationController {
...
}

But the most important thing to do was this in my app-config:

@Configuration
// @EnableWebMvc  IF ENABLED SWAGGER-UI WON'T WORK
@EnableSwagger2
@ComponentScan(basePackages = "de.bluewhale.sabi")
@PropertySource("classpath:application.properties")
public class AppConfig { 
5reactions
chrisinmtowncommented, Jul 19, 2017

Our Spring (but not spring-boot) app uses the @ annotation EnableWebMvc. To make swagger work we add a config class:

@Configuration
@EnableWebMvc
public class SwaggerMVCConfig extends WebMvcConfigurerAdapter {

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger-ui.html is giving blank page - Stack Overflow
I am using url https://localhost:8080/context-path/swagger-ui/ I am able to get the JSON data for url https://localhost:8080/context-path/v2/api ...
Read more >
Springfox Reference Documentation - GitHub Pages
Springfox works by examining an application, once, at runtime to infer API semantics based on spring configurations, class structure and various ...
Read more >
docs/release-notes.md · serv/springfox - Gitee.com
... api_docs shows content but swagger-ui (2.6.1) is empty @StefanSchubert; (#1613) HTML code in API description in ignored using springfox-swagger-ui 2.6.1 ...
Read more >
F.A.Q - Springdoc-openapi
springdoc.swagger-ui.path= /swagger-ui/api-docs.html ... It is be possible to handle as return an empty content as response using, one of the following ...
Read more >
Spring Boot RESTful API Documentation with Swagger 2
Swagger 2 is a very popular tool set for documenting RESTful interfaces developed with Spring Boot. In this post I show you how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found