X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2FSwaggerConfig.java;h=ddcf0d35498134e3ff38dc2ff1b3425af1ddeeee;hb=6a39814272307d0207222c9229b0d765ac062bf0;hp=cfb9a506ad6843088eb185b03542f43f2cefd265;hpb=218b9d1686e76c4ded2d39e21f6667375f3b72d7;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java index cfb9a506..ddcf0d35 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java @@ -20,27 +20,74 @@ package org.oransc.policyagent; +import com.google.common.base.Predicates; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; 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; /** - * Swagger configuration class that uses swagger2 documentation type and scans all the controllers - * under org.oransc.policyagent.controllers package. To access the swagger gui go to - * http://ip:port/swagger-ui.html + * Swagger configuration class that uses swagger2 documentation type and scans + * all the controllers under org.oransc.policyagent.controllers package. To + * access the swagger gui go to http://ip:port/swagger-ui.html * */ @Configuration @EnableSwagger2 -public class SwaggerConfig { - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2).select() - .apis(RequestHandlerSelectors.basePackage("org.oransc.policyagent.controllers")) - .paths(PathSelectors.any()).build(); - } +public class SwaggerConfig extends WebMvcConfigurationSupport { + + static final String API_TITLE = "A1 Policy management service"; + static final String DESCRIPTION = "This page lists all the rest apis for the service."; + static final String VERSION = "1.0"; + @SuppressWarnings("squid:S1075") // Refactor your code to get this URI from a customizable parameter. + static final String RESOURCES_PATH = "classpath:/META-INF/resources/"; + static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/"; + static final String SWAGGER_UI = "swagger-ui.html"; + static final String WEBJARS = "/webjars/**"; + + /** + * Gets the API info. + * + * @return the API info. + */ + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) // + .apiInfo(apiInfo()) // + .select() // + .apis(RequestHandlerSelectors.any()) // + .paths(PathSelectors.any()) // + .paths(Predicates.not(PathSelectors.regex("/error"))) // + // this endpoint is not implemented, but was visible for Swagger + .paths(Predicates.not(PathSelectors.regex("/actuator.*"))) // + // this endpoint is implemented by spring framework, exclude for now + .build(); + } + + private static ApiInfo apiInfo() { + return new ApiInfoBuilder() // + .title(API_TITLE) // + .description(DESCRIPTION) // + .version(VERSION) // + .build(); + } + + @Override + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler(SWAGGER_UI) // + .addResourceLocations(RESOURCES_PATH); + + registry.addResourceHandler(WEBJARS) // + .addResourceLocations(WEBJARS_PATH); + } + }