Swagger-UI using Spring framework
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>
Thu, 5 Nov 2020 11:34:41 +0000 (11:34 +0000)
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>
Fri, 6 Nov 2020 11:18:31 +0000 (11:18 +0000)
JIRA: https://jira.onap.org/browse/CCSDK-2895

Issue-ID: CCSDK-2895
Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca>
Change-Id: I6e9e4b93aec25b0dd7a1acd3612140de47320d3c

cps/README.md
cps/cps-dependencies/pom.xml
cps/cps-parent/pom.xml
cps/cps-rest/pom.xml
cps/cps-rest/src/main/java/org/onap/cps/swagger/config/SpringFoxConfig.java [new file with mode: 0644]
cps/cps-rest/src/main/resources/application.yml

index d1bf49d..d5f0c66 100644 (file)
@@ -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)
index ad71b11..ee37b1e 100644 (file)
@@ -17,7 +17,7 @@
         <hibernate-types.version>2.10.0</hibernate-types.version>
         <spock-core.version>2.0-M2-groovy-3.0</spock-core.version>
         <springboot.version>2.3.3.RELEASE</springboot.version>
-        <springfox-swagger2.version>2.6.1</springfox-swagger2.version>
+        <springfox.version>3.0.0</springfox.version>
         <swagger.version>2.1.4</swagger.version>
         <yangtools.version>5.0.6</yangtools.version>
     </properties>
                 <artifactId>swagger-annotations</artifactId>
                 <version>${swagger.version}</version>
             </dependency>
-            <dependency>
-                <groupId>io.swagger.core.v3</groupId>
-                <artifactId>swagger-jaxrs2</artifactId>
-                <version>${swagger.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>io.springfox</groupId>
-                <artifactId>springfox-swagger2</artifactId>
-                <version>${springfox-swagger2.version}</version>
-            </dependency>
             <dependency>
                 <groupId>io.springfox</groupId>
-                <artifactId>springfox-swagger-ui</artifactId>
-                <version>${springfox-swagger2.version}</version>
+                <artifactId>springfox-boot-starter</artifactId>
+                <version>${springfox.version}</version>
             </dependency>
             <dependency>
                 <groupId>com.vladmihalcea</groupId>
index db80970..04f423c 100644 (file)
 
     <properties>
         <java.version>11</java.version>
-        <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
-        <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
-        <maven-replacer-plugin.version>1.5.3</maven-replacer-plugin.version>
         <oparent.version>3.1.0</oparent.version>
         <spring-boot-maven-plugin.version>2.3.3.RELEASE</spring-boot-maven-plugin.version>
         <swagger-codegen-maven-plugin.version>3.0.18</swagger-codegen-maven-plugin.version>
-        <swagger-ui.version>3.35.0</swagger-ui.version>
     </properties>
 
     <dependencyManagement>
                         </execution>
                     </executions>
                 </plugin>
-                <plugin>
-                    <!-- Download Swagger UI webjar. -->
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-dependency-plugin</artifactId>
-                    <version>${maven-dependency-plugin.version}</version>
-                    <executions>
-                        <execution>
-                            <phase>prepare-package</phase>
-                            <goals>
-                                <goal>unpack</goal>
-                            </goals>
-                            <configuration>
-                                <artifactItems>
-                                    <artifactItem>
-                                        <groupId>org.webjars</groupId>
-                                        <artifactId>swagger-ui</artifactId>
-                                        <version>${swagger-ui.version}</version>
-                                    </artifactItem>
-                                </artifactItems>
-                                <outputDirectory>
-                                    ${project.build.directory}/swagger-ui-${swagger-ui.version}
-                                </outputDirectory>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
-                <plugin>
-                    <!-- Copy Swagger UI resources to static resources directory. -->
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>${maven-resources-plugin.version}</version>
-                    <executions>
-                        <execution>
-                            <id>copy-resources</id>
-                            <phase>prepare-package</phase>
-                            <goals>
-                                <goal>copy-resources</goal>
-                            </goals>
-                            <configuration>
-                                <outputDirectory>${project.build.outputDirectory}/static/swagger-ui
-                                </outputDirectory>
-                                <resources>
-                                    <resource>
-                                        <directory>
-                                            ${project.build.directory}/swagger-ui-${swagger-ui.version}/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}/
-                                        </directory>
-                                        <excludes>
-                                            <exclude>**/*.gz</exclude>
-                                        </excludes>
-                                    </resource>
-                                </resources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
-                <plugin>
-                    <!-- Replace the OpenAPI specification example URL with the local one. -->
-                    <groupId>com.google.code.maven-replacer-plugin</groupId>
-                    <artifactId>replacer</artifactId>
-                    <version>${maven-replacer-plugin.version}</version>
-                    <executions>
-                        <execution>
-                            <phase>prepare-package</phase>
-                            <goals>
-                                <goal>replace</goal>
-                            </goals>
-                        </execution>
-                    </executions>
-                    <configuration>
-                        <file>${project.build.outputDirectory}/static/swagger-ui/index.html</file>
-                        <replacements>
-                            <replacement>
-                                <token>https://petstore.swagger.io/v2/swagger.json</token>
-                                <value>/api/cps/openapi.json</value>
-                            </replacement>
-                        </replacements>
-                    </configuration>
-                </plugin>
             </plugins>
         </pluginManagement>
         <plugins>
index fcd97dc..d10e0b6 100644 (file)
             <groupId>io.swagger.core.v3</groupId>\r
             <artifactId>swagger-annotations</artifactId>\r
         </dependency>\r
-        <dependency>\r
-            <groupId>io.swagger.core.v3</groupId>\r
-            <artifactId>swagger-jaxrs2</artifactId>\r
-        </dependency>\r
         <dependency>\r
             <groupId>io.springfox</groupId>\r
-            <artifactId>springfox-swagger2</artifactId>\r
-        </dependency>\r
-        <dependency>\r
-            <groupId>io.springfox</groupId>\r
-            <artifactId>springfox-swagger-ui</artifactId>\r
+            <artifactId>springfox-boot-starter</artifactId>\r
         </dependency>\r
+\r
         <dependency>\r
             <groupId>org.springframework.boot</groupId>\r
             <artifactId>spring-boot-starter-test</artifactId>\r
                 <groupId>io.swagger.codegen.v3</groupId>\r
                 <artifactId>swagger-codegen-maven-plugin</artifactId>\r
             </plugin>\r
-            <plugin>\r
-                <!-- Download Swagger UI webjar. -->\r
-                <groupId>org.apache.maven.plugins</groupId>\r
-                <artifactId>maven-dependency-plugin</artifactId>\r
-            </plugin>\r
-            <plugin>\r
-                <!-- Copy Swagger UI resources to static resources directory. -->\r
-                <groupId>org.apache.maven.plugins</groupId>\r
-                <artifactId>maven-resources-plugin</artifactId>\r
-            </plugin>\r
-            <plugin>\r
-                <!-- Replace the OpenAPI specification example URL with the local one. -->\r
-                <groupId>com.google.code.maven-replacer-plugin</groupId>\r
-                <artifactId>replacer</artifactId>\r
-            </plugin>\r
         </plugins>\r
     </build>\r
 </project>\r
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 (file)
index 0000000..73e1795
--- /dev/null
@@ -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();
+    }
+}
index 8e2aee0..545faaf 100644 (file)
@@ -1,7 +1,7 @@
 server:\r
-  port: 8080\r
-  servlet:\r
-     context-path: /api/cps\r
+    port: 8080\r
+    servlet:\r
+        context-path: /api/cps\r
 \r
 spring:\r
     main:\r
@@ -21,8 +21,6 @@ spring:
         password: ${DB_PASSWORD}\r
         driverClassName: org.postgresql.Driver\r
         initialization-mode: always\r
-    jersey:\r
-        type: filter\r
 \r
 logging:\r
     level:\r