1990efb82f8d7e89e8900578febb27fac8b6d76a
[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
23 import org.springframework.context.annotation.Bean;
24 import org.springframework.context.annotation.Configuration;
25 import org.springframework.context.annotation.Profile;
26 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
27 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
28
29 import springfox.documentation.builders.ApiInfoBuilder;
30 import springfox.documentation.builders.PathSelectors;
31 import springfox.documentation.builders.RequestHandlerSelectors;
32 import springfox.documentation.service.ApiInfo;
33 import springfox.documentation.spi.DocumentationType;
34 import springfox.documentation.spring.web.plugins.Docket;
35 import springfox.documentation.swagger2.annotations.EnableSwagger2;
36
37 @EnableSwagger2
38 @Configuration
39 @Profile("prod")
40 public class SwaggerConfig extends WebMvcConfigurationSupport {
41     static final String API_TITLE = "DATAFILE app server";
42     static final String DESCRIPTION = "This page lists all the rest apis for DATAFILE app server.";
43     static final String VERSION = "1.0";
44     static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
45     static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
46     static final String SWAGGER_UI = "swagger-ui.html";
47     static final String WEBJARS = "/webjars/**";
48
49     /**
50      * Gets the API info.
51      *
52      * @return the API info.
53      */
54     @Bean
55     public Docket api() {
56         return new Docket(DocumentationType.SWAGGER_2) //
57             .apiInfo(apiInfo()) //
58             .select() //
59             .apis(RequestHandlerSelectors.any()) //
60             .paths(PathSelectors.any()) //
61             .paths(Predicates.not(PathSelectors.regex("/error"))) //
62             // this endpoint is not implemented, but was visible for Swagger
63             .build();
64     }
65
66     private static ApiInfo apiInfo() {
67         return new ApiInfoBuilder() //
68             .title(API_TITLE) //
69             .description(DESCRIPTION) //
70             .version(VERSION) //
71             .build();
72     }
73
74     @Override
75     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
76         registry.addResourceHandler(SWAGGER_UI) //
77             .addResourceLocations(RESOURCES_PATH);
78
79         registry.addResourceHandler(WEBJARS) //
80             .addResourceLocations(WEBJARS_PATH);
81     }
82 }