web-dev-qa-db-fra.com

Comment changer le préfixe d'URL Swagger-ui?

J'utilise Springfox Swagger2 avec Spring boot 1.5.9.

Je peux accéder à l'interface utilisateur de swagger sur ce lien.

http: // localhost: 8090/swagger-ui.html

Comment puis-je le modifier pour qu'il soit disponible sur l'URL suivante?

http: // localhost: 8090/my/custom/path/swagger-ui.html

@EnableSwagger2
public class Configuration {

@Bean
public Docket api() { 
    return new Docket(DocumentationType.SWAGGER_2)  
      .select()
      .apis(RequestHandlerSelectors.basePackage("my.favorite.package"))
      .paths(PathSelectors.any())
      .build()
      .apiInfo(apiInfo()).useDefaultResponseMessages(false);
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("My title").version("1.0")
            .contact(new Contact("Blah", "blah.com", "[email protected]")).build();
}
}
5
Ravi Gupta

Essayez cette classe de configuration.

@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {

  @Bean
  public Docket productApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select().apis(RequestHandlerSelectors.basePackage(""my.favorite.package""))
                        .paths(regex(PathSelectors.any()))
        .build();

  }

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs").setKeepQueryParams(true);
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
    registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
  }

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


}
3
Hatice