From: Rishi Chail Date: Fri, 2 Oct 2020 08:33:35 +0000 (+0100) Subject: DM: Enable Swagger X-Git-Tag: 0.0.1~120^2~17 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=14f3af1327204bdeee57241bd094b426e0741312;p=cps.git DM: Enable Swagger Issue-ID: CCSDK-2754 https: //jira.onap.org/browse/CCSDK-2754 Change-Id: I20f8ab029082bb0012d5933f47d15a2f482ee378 Signed-off-by: Rishi Chail --- diff --git a/cps/cps-rest/pom.xml b/cps/cps-rest/pom.xml index bd9be8dfde..2b4cbb8940 100644 --- a/cps/cps-rest/pom.xml +++ b/cps/cps-rest/pom.xml @@ -44,6 +44,17 @@ spring-boot-starter-jetty + + io.swagger.core.v3 + swagger-annotations + ${swagger.version} + + + + io.swagger.core.v3 + swagger-jaxrs2 + ${swagger.version} + org.springframework.boot diff --git a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java index 44487fe068..ea273986c8 100644 --- a/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java +++ b/cps/cps-rest/src/main/java/org/onap/cps/rest/config/JerseyConfig.java @@ -20,20 +20,38 @@ package org.onap.cps.rest.config; +import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder; +import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource; +import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource; +import io.swagger.v3.oas.integration.OpenApiConfigurationException; import javax.annotation.PostConstruct; import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.server.ResourceConfig; -import org.onap.cps.rest.controller.RestController; import org.springframework.context.annotation.Configuration; @Configuration @ApplicationPath("/api/v1") public class JerseyConfig extends ResourceConfig { + /** + * This method is used to setup Jersey related configuration. + */ @PostConstruct public void init() { - register(RestController.class); register(MultiPartFeature.class); + register(OpenApiResource.class); + register(AcceptHeaderOpenApiResource.class); + + packages("org.onap.cps.rest.controller"); + configureSwagger(); + } + + private void configureSwagger() { + try { + new JaxrsOpenApiContextBuilder<>().buildContext(true).read(); + } catch (final OpenApiConfigurationException e) { + throw new RuntimeException(e.getMessage(), e); + } } -} \ No newline at end of file +} diff --git a/cps/cps-rest/src/main/resources/openapi-configuration.json b/cps/cps-rest/src/main/resources/openapi-configuration.json new file mode 100644 index 0000000000..ad5998feb7 --- /dev/null +++ b/cps/cps-rest/src/main/resources/openapi-configuration.json @@ -0,0 +1,28 @@ +{ + "resourcePackages": [ + "org.onap.cps.rest.controller" + ], + "prettyPrint": true, + "cacheTTL": 0, + "openAPI": { + "info": { + "title": "ONAP Open API v3 CPS Spec", + "description": "The API Description may be multiline, and GitHub Flavored Markdown, GFM syntax, can be used for rich text representation.", + "x-logo": { + "url": "logo.png" + }, + "contact": { + "name": "ONAP", + "url": "https://onap.readthedocs.io", + "email": "onap-discuss@lists.onap.org" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0" + }, + "version": "1.2.34", + "x-planned-retirement-date": "202207", + "x-component": "Modeling" + } + } +} diff --git a/cps/cps-service/pom.xml b/cps/cps-service/pom.xml index a59376c20f..731873420c 100644 --- a/cps/cps-service/pom.xml +++ b/cps/cps-service/pom.xml @@ -14,26 +14,26 @@ org.opendaylight.yangtools yang-parser-api - ${org.opendaylight.yangtools.version} + ${yangtools.version} org.opendaylight.yangtools yang-parser-impl - ${org.opendaylight.yangtools.version} + ${yangtools.version} org.opendaylight.yangtools yang-model-util - ${org.opendaylight.yangtools.version} + ${yangtools.version} org.opendaylight.yangtools yang-data-codec-gson - ${org.opendaylight.yangtools.version} + ${yangtools.version} @@ -64,13 +64,13 @@ org.codehaus.groovy groovy - ${version.groovy} + ${groovy.version} test org.spockframework spock-core - ${version.spock-core} + ${spock-core.version} test diff --git a/cps/pom.xml b/cps/pom.xml index 5435c4a4a6..d81ee9e08e 100644 --- a/cps/pom.xml +++ b/cps/pom.xml @@ -19,12 +19,13 @@ - 11 + 11 2.3.3.RELEASE 3.1.0 - 5.0.5 - 3.0.6 - 2.0-M2-groovy-3.0 + 5.0.6 + 2.1.4 + 3.0.6 + 2.0-M2-groovy-3.0 @@ -67,8 +68,8 @@ org.apache.maven.plugins maven-compiler-plugin - ${version.java.compiler} - ${version.java.compiler} + ${java.version} + ${java.version}