1

I want to use Swagger 2.0 with my Spring Boot RESTful web service to generate documentation. I have searched quite a bit for an answer to this. Basically I have a Spring Boot project with a set of controllers and I want to document the API's. I have the following dependencies setup in my POM file.

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.5.0</version>
    </dependency>

This is my Swagger configuration class with the @Configuration and @EnableSwagger2:

      @Configuration
      @EnableSwagger2
public class SwaggerConfig {

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

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("My application title")
            .description("This is a test of documenting EST API's")
            .version("V1.2")
            .termsOfServiceUrl("http://terms-of-services.url")
            .license("LICENSE")
            .licenseUrl("http://url-to-license.com")
            .build();
    }

}

From what I have gathered in reading a couple of other answers here that at this point I should be able to see something at a URL such as http://myapp/v2/api-docs or alternatively http://localhost:8080/myapp/api-docs I have made the assumption that the "myapp" portion of the above URL refers to the name of the class in which my main resides (is this correct)? Also I have tried this with port 8080 and port 80 and the bottom line is that I see nothing other than site can't be reached. I have looked at the answers provided here and here however I'm not having any success. Any help would be much appreciated, thank you in advance.

Community
  • 1
  • 1
TKPhillyBurb
  • 81
  • 1
  • 10

2 Answers2

1

As you can see on the following documentation : https://springfox.github.io/springfox/docs/snapshot/#springfox-swagger-ui

The endpoint is now on swagger-ui.html, for your case, it will be http://localhost:8080/myapp/swagger-ui.html

fbak
  • 11
  • 3
0

I used, <artifactId>springdoc-openapi-ui</artifactId> with

public class OpenApiConfiguration{

     @Bean
     public GroupedOpenApi abcApp(){
        String[] abcAppRootPath={"com.stockoverflow.swagger"};
        return GroupedOpenApi.builder().group("my app").packagesToScan(abcAppRootPath).build();
    }
}

reference : https://springdoc.org/#getting-started

Suraj Rao
  • 28,850
  • 10
  • 94
  • 99
G Krishna
  • 91
  • 1
  • 4