2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oransc.enrichment;
23 import com.fasterxml.classmate.TypeResolver;
24 import com.google.common.base.Predicates;
26 import org.oransc.enrichment.clients.ProducerJobInfo;
27 import org.oransc.enrichment.controllers.consumer.ConsumerEiJobInfo;
28 import org.oransc.enrichment.controllers.producer.ProducerEiTypeInfo;
29 import org.oransc.enrichment.controllers.producer.ProducerRegistrationInfo;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
33 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
35 import springfox.documentation.builders.ApiInfoBuilder;
36 import springfox.documentation.builders.PathSelectors;
37 import springfox.documentation.builders.RequestHandlerSelectors;
38 import springfox.documentation.service.ApiInfo;
39 import springfox.documentation.spi.DocumentationType;
40 import springfox.documentation.spring.web.plugins.Docket;
41 import springfox.documentation.swagger2.annotations.EnableSwagger2;
44 * Swagger configuration class that uses swagger2 documentation type and scans
45 * all the controllers. To access the swagger gui go to
46 * http://ip:port/swagger-ui.html
50 public class SwaggerConfig extends WebMvcConfigurationSupport {
52 static final String API_TITLE = "Enrichment Data service";
53 static final String DESCRIPTION = "This page lists all the rest apis for the service.";
54 static final String VERSION = "1.0";
55 @SuppressWarnings("squid:S1075") // Refactor your code to get this URI from a customizable parameter.
56 static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
57 static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
58 static final String SWAGGER_UI = "swagger-ui.html";
59 static final String WEBJARS = "/webjars/**";
64 * @return the API info.
67 public Docket api(TypeResolver resolver) {
68 return new Docket(DocumentationType.SWAGGER_2) //
69 .apiInfo(apiInfo()) //
70 .additionalModels(resolver.resolve(ConsumerEiJobInfo.class)) //
71 .additionalModels(resolver.resolve(ProducerRegistrationInfo.class)) //
72 .additionalModels(resolver.resolve(ProducerEiTypeInfo.class)) //
73 .additionalModels(resolver.resolve(ProducerJobInfo.class)) //
75 .apis(RequestHandlerSelectors.any()) //
76 .paths(PathSelectors.any()) //
77 .paths(Predicates.not(PathSelectors.regex("/error"))) //
78 // this endpoint is not implemented, but was visible for Swagger
79 .paths(Predicates.not(PathSelectors.regex("/actuator.*"))) //
80 // this endpoint is implemented by spring framework, exclude for now
84 private static ApiInfo apiInfo() {
85 return new ApiInfoBuilder() //
87 .description(DESCRIPTION) //
93 protected void addResourceHandlers(ResourceHandlerRegistry registry) {
94 registry.addResourceHandler(SWAGGER_UI) //
95 .addResourceLocations(RESOURCES_PATH);
97 registry.addResourceHandler(WEBJARS) //
98 .addResourceLocations(WEBJARS_PATH);