0

Hi' I have several REST api in my spring mvc project and I would like to create documentation for each service and store it in file so I can share with the team. I often read about Swagger or Springfox and configure it so, I added

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.2.2</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.7.0-rc1</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.1.2</version>
</dependency>

and config class:

package com.config.core;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static springfox.documentation.builders.PathSelectors.*;
@Configuration
@EnableSwagger2
public class SwaggerConfig {

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

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
            "My Project's REST API",
            "1.0",
            "This is a description of your API.",
            "API TOS",
            "me@wherever.com",
            "API License",
            "API License URL"
        );
        return apiInfo;
    }
}

but swagger-ui.html doesn't exist, I have :

> /v2/api-docs 
> /configuration/security
> /configuration/ui 
> /swagger-resources

So, how can I see my web server documentation and save it on file? I would like to avoid to show on url when users have to use the web platform.Thanks

luca
  • 3,248
  • 10
  • 66
  • 145

1 Answers1

0

springfox-swagger-ui is a webjar and the resources embedded in the jar need to be registered via resource handlers.

You need to add the resource handlers as demonstrated in the spring mvc demo. That way the swagger ui assets can be rendered by the application.

Dilip Krishnan
  • 5,417
  • 3
  • 37
  • 53