712422655cbbc512a87a3f7bca9c04c43a761a2e
[dcaegen2/collectors/datafile.git] /
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package org.onap.dcaegen2.collectors.datafile.configuration;
20
21 import com.google.common.base.Predicates;
22 import org.springframework.context.annotation.Bean;
23 import org.springframework.context.annotation.Configuration;
24 import org.springframework.context.annotation.Profile;
25 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
26 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
27 import springfox.documentation.builders.ApiInfoBuilder;
28 import springfox.documentation.builders.PathSelectors;
29 import springfox.documentation.builders.RequestHandlerSelectors;
30 import springfox.documentation.service.ApiInfo;
31 import springfox.documentation.spi.DocumentationType;
32 import springfox.documentation.spring.web.plugins.Docket;
33 import springfox.documentation.swagger2.annotations.EnableSwagger2;
34
35
36 @EnableSwagger2
37 @Configuration
38 @Profile("prod")
39 public class SwaggerConfig extends WebMvcConfigurationSupport {
40     static final String API_TITLE = "DATAFILE app server";
41     static final String DESCRIPTION = "This page lists all the rest apis for DATAFILE app server.";
42     static final String VERSION = "1.0";
43     static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
44     static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
45     static final String SWAGGER_UI = "swagger-ui.html";
46     static final String WEBJARS = "/webjars/**";
47
48     /**
49      * Gets the API info.
50      *
51      * @return the API info.
52      */
53     @Bean
54     public Docket api() {
55         return new Docket(DocumentationType.SWAGGER_2) //
56                 .apiInfo(apiInfo()) //
57                 .select() //
58                 .apis(RequestHandlerSelectors.any()) //
59                 .paths(PathSelectors.any()) //
60                 .paths(Predicates.not(PathSelectors.regex("/error"))) //
61                 // this endpoint is not implemented, but was visible for Swagger
62                 .build();
63     }
64
65     private ApiInfo apiInfo() {
66         return new ApiInfoBuilder() //
67                 .title(API_TITLE) //
68                 .description(DESCRIPTION) //
69                 .version(VERSION) //
70                 .build();
71     }
72
73     @Override
74     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
75         registry.addResourceHandler(SWAGGER_UI) //
76                 .addResourceLocations(RESOURCES_PATH);
77
78         registry.addResourceHandler(WEBJARS) //
79                 .addResourceLocations(WEBJARS_PATH);
80     }
81 }