c3c87da2ee7772446a7f4bd8330d20cf0841e373
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.bbs.event.processor.config;
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("production")
40 public class SwaggerConfiguration extends WebMvcConfigurationSupport {
41
42     private static final String PACKAGE_PATH = "org.onap.bbs.event.processor";
43     private static final String API_TITLE = "BBS Event Processor";
44     private static final String DESCRIPTION = "This page lists bbs-event-processor REST API details";
45     private static final String VERSION = "1.0";
46     private static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
47     private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
48     private static final String SWAGGER_UI = "swagger-ui.html";
49     private static final String WEBJARS = "/webjars/**";
50
51     /**
52      * Swagger configuration function for hosting it next to spring http website.
53      *
54      * @return Docket
55      */
56     @Bean
57     public Docket api() {
58         return new Docket(DocumentationType.SWAGGER_2)
59                 .apiInfo(apiInfo())
60                 .select()
61                 .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
62                 .paths(PathSelectors.any())
63                 .build();
64     }
65
66     private ApiInfo apiInfo() {
67         return new ApiInfoBuilder()
68                 .title(API_TITLE)
69                 .description(DESCRIPTION)
70                 .version(VERSION)
71                 .build();
72     }
73
74
75     @Override
76     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
77         registry.addResourceHandler(SWAGGER_UI)
78                 .addResourceLocations(RESOURCES_PATH);
79
80         registry.addResourceHandler(WEBJARS)
81                 .addResourceLocations(WEBJARS_PATH);
82     }
83 }