Search code examples
swagger-2.0springfox

Swagger UI doesn't show module name in its url and


I have followed https://dzone.com/articles/spring-boot-restful-api-documentation-with-swagger and developing the Swagger using the springfox-swagger-ui and springfox-swagger2 version 2.9.2.

I used the below configurations, but I want module-name to be printed out here. Also, @Api(tags = "User Catalouge", description = "List Of Users"), description is deprecated.

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("guru.springframework.controllers"))
                .paths(regex("/product.*"))
                .build()
                .apiInfo(metaData());
    }
    private ApiInfo metaData() {
        ApiInfo apiInfo = new ApiInfo(
                "Spring Boot REST API",
                "Spring Boot REST API for Online Store",
                "1.0",
                "Terms of service",
                new Contact("John Thompson", "https://springframework.guru/about/", "[email protected]"),
               "Apache License Version 2.0",
                "https://www.apache.org/licenses/LICENSE-2.0");
        return apiInfo;
    }
}

enter image description here


Solution

  • You just need to set the servlet context path. Spring Boot & Swagger are smart enough to recognized the URL and take it in the url.

    server.servlet.context-path=/product-details