Merge "Running Dmaap consumer in a seprate thread"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / SwaggerConfig.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
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.oransc.policyagent;
22
23 import com.google.common.base.Predicates;
24
25 import org.springframework.context.annotation.Bean;
26 import org.springframework.context.annotation.Configuration;
27 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
28 import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
29
30 import springfox.documentation.builders.ApiInfoBuilder;
31 import springfox.documentation.builders.PathSelectors;
32 import springfox.documentation.builders.RequestHandlerSelectors;
33 import springfox.documentation.service.ApiInfo;
34 import springfox.documentation.spi.DocumentationType;
35 import springfox.documentation.spring.web.plugins.Docket;
36 import springfox.documentation.swagger2.annotations.EnableSwagger2;
37
38 /**
39  * Swagger configuration class that uses swagger2 documentation type and scans all the controllers
40  * under org.oransc.policyagent.controllers package. To access the swagger gui go to
41  * http://ip:port/swagger-ui.html
42  *
43  */
44 @Configuration
45 @EnableSwagger2
46 public class SwaggerConfig extends WebMvcConfigurationSupport {
47
48     static final String API_TITLE = "Policy server";
49     static final String DESCRIPTION = "This page lists all the rest apis for Policy server.";
50     static final String VERSION = "1.0";
51     static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
52     static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
53     static final String SWAGGER_UI = "swagger-ui.html";
54     static final String WEBJARS = "/webjars/**";
55
56     /**
57      * Gets the API info.
58      *
59      * @return the API info.
60      */
61     @Bean
62     public Docket api() {
63         return new Docket(DocumentationType.SWAGGER_2) //
64             .apiInfo(apiInfo()) //
65             .select() //
66             .apis(RequestHandlerSelectors.any()) //
67             .paths(PathSelectors.any()) //
68             .paths(Predicates.not(PathSelectors.regex("/error"))) //
69             // this endpoint is not implemented, but was visible for Swagger
70             .build();
71     }
72
73     private static ApiInfo apiInfo() {
74         return new ApiInfoBuilder() //
75             .title(API_TITLE) //
76             .description(DESCRIPTION) //
77             .version(VERSION) //
78             .build();
79     }
80
81     @Override
82     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
83         registry.addResourceHandler(SWAGGER_UI) //
84             .addResourceLocations(RESOURCES_PATH);
85
86         registry.addResourceHandler(WEBJARS) //
87             .addResourceLocations(WEBJARS_PATH);
88     }
89
90 }