From 52cff68a4eed173059d3cda05435786f24cdf95e Mon Sep 17 00:00:00 2001 From: "puthuparambil.aditya" Date: Thu, 5 Nov 2020 11:34:41 +0000 Subject: [PATCH] Swagger-UI using Spring framework JIRA: https://jira.onap.org/browse/CCSDK-2895 Issue-ID: CCSDK-2895 Signed-off-by: puthuparambil.aditya Change-Id: I6e9e4b93aec25b0dd7a1acd3612140de47320d3c --- cps/README.md | 5 +- cps/cps-dependencies/pom.xml | 16 +---- cps/cps-parent/pom.xml | 82 ---------------------- cps/cps-rest/pom.xml | 26 +------ .../onap/cps/swagger/config/SpringFoxConfig.java | 46 ++++++++++++ cps/cps-rest/src/main/resources/application.yml | 8 +-- 6 files changed, 56 insertions(+), 127 deletions(-) create mode 100644 cps/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java diff --git a/cps/README.md b/cps/README.md index d1bf49d8c..d5f0c66f4 100644 --- a/cps/README.md +++ b/cps/README.md @@ -29,6 +29,5 @@ java -DDB_HOST=localhost -DDB_USERNAME=cps -DDB_PASSWORD=cps -jar cps-rest/targe ``` * Browse - * [Swagger UI](http://localhost:8080/swagger-ui/index.html) - * OpenAPI Specification in [JSON](http://localhost:8080/api/cps/openapi.json) - or [YAML](http://localhost:8080/api/cps/openapi.yaml) format + * [Swagger UI](http://localhost:8080/api/cps/swagger-ui/index.html) + * [Api Documentation](http://localhost:8080/api/cps/v3/api-docs) diff --git a/cps/cps-dependencies/pom.xml b/cps/cps-dependencies/pom.xml index ad71b1158..ee37b1e0a 100644 --- a/cps/cps-dependencies/pom.xml +++ b/cps/cps-dependencies/pom.xml @@ -17,7 +17,7 @@ 2.10.0 2.0-M2-groovy-3.0 2.3.3.RELEASE - 2.6.1 + 3.0.0 2.1.4 5.0.6 @@ -43,20 +43,10 @@ swagger-annotations ${swagger.version} - - io.swagger.core.v3 - swagger-jaxrs2 - ${swagger.version} - - - io.springfox - springfox-swagger2 - ${springfox-swagger2.version} - io.springfox - springfox-swagger-ui - ${springfox-swagger2.version} + springfox-boot-starter + ${springfox.version} com.vladmihalcea diff --git a/cps/cps-parent/pom.xml b/cps/cps-parent/pom.xml index db80970c5..04f423caa 100644 --- a/cps/cps-parent/pom.xml +++ b/cps/cps-parent/pom.xml @@ -17,13 +17,9 @@ 11 - 3.2.0 - 3.1.2 - 1.5.3 3.1.0 2.3.3.RELEASE 3.0.18 - 3.35.0 @@ -106,84 +102,6 @@ - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - prepare-package - - unpack - - - - - org.webjars - swagger-ui - ${swagger-ui.version} - - - - ${project.build.directory}/swagger-ui-${swagger-ui.version} - - - - - - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - copy-resources - prepare-package - - copy-resources - - - ${project.build.outputDirectory}/static/swagger-ui - - - - - ${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/ - - - **/*.gz - - - - - - - - - - com.google.code.maven-replacer-plugin - replacer - ${maven-replacer-plugin.version} - - - prepare-package - - replace - - - - - ${project.build.outputDirectory}/static/swagger-ui/index.html - - - https://petstore.swagger.io/v2/swagger.json - /api/cps/openapi.json - - - - diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml index fcd97dcf7..d10e0b63b 100644 --- a/cps/cps-rest/pom.xml +++ b/cps/cps-rest/pom.xml @@ -38,18 +38,11 @@ io.swagger.core.v3 swagger-annotations - - io.swagger.core.v3 - swagger-jaxrs2 - io.springfox - springfox-swagger2 - - - io.springfox - springfox-swagger-ui + springfox-boot-starter + org.springframework.boot spring-boot-starter-test @@ -74,21 +67,6 @@ io.swagger.codegen.v3 swagger-codegen-maven-plugin - - - org.apache.maven.plugins - maven-dependency-plugin - - - - org.apache.maven.plugins - maven-resources-plugin - - - - com.google.code.maven-replacer-plugin - replacer - diff --git a/cps/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java b/cps/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java new file mode 100644 index 000000000..73e179511 --- /dev/null +++ b/cps/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.swagger.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +/** + * Swagger configuration. + */ +@Configuration +public class SpringFoxConfig { + + /** + * Define api configuration. + */ + @Bean + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + } +} diff --git a/cps/cps-rest/src/main/resources/application.yml b/cps/cps-rest/src/main/resources/application.yml index 8e2aee043..545faafc3 100644 --- a/cps/cps-rest/src/main/resources/application.yml +++ b/cps/cps-rest/src/main/resources/application.yml @@ -1,7 +1,7 @@ server: - port: 8080 - servlet: - context-path: /api/cps + port: 8080 + servlet: + context-path: /api/cps spring: main: @@ -21,8 +21,6 @@ spring: password: ${DB_PASSWORD} driverClassName: org.postgresql.Driver initialization-mode: always - jersey: - type: filter logging: level: -- 2.16.6