Replace SpringFox with SpringDoc in policy-pap 44/132644/1
authorliamfallon <liam.fallon@est.tech>
Thu, 8 Dec 2022 18:44:09 +0000 (18:44 +0000)
committerliamfallon <liam.fallon@est.tech>
Thu, 8 Dec 2022 18:44:13 +0000 (18:44 +0000)
This commit:
- Remove SpringFox
- Adds SpringDoc
- Enables the .../v3/api-docs endpoint

Note that the Swagger annotations from the OpenAPI specification
generated code need to be enabled so that the API specification is
available over the ..../v3/api-docs endpoint. THis will be done in
subsequent commits.

Issue-ID: POLICY-4404
Change-Id: I42c1575a3ce76d9b3e753ad51f85df027d12b980
Signed-off-by: liamfallon <liam.fallon@est.tech>
main/pom.xml
main/src/main/java/org/onap/policy/pap/main/PolicyPapApplication.java
main/src/main/java/org/onap/policy/pap/main/config/SpringDocBean.java [new file with mode: 0644]
main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
main/src/test/java/org/onap/policy/pap/main/rest/PapRestControllerV1Test.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java

index d018e69..bd42087 100644 (file)
             <version>${version.io.micrometer}</version>
             <scope>runtime</scope>
         </dependency>
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-boot-starter</artifactId>
-            <version>${version.springfox}</version>
-        </dependency>
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <scope>runtime</scope>
-        </dependency>
         <dependency>
             <groupId>org.apache.kafka</groupId>
             <artifactId>kafka-clients</artifactId>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-ui</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
index edb6ff6..cfa5c02 100644 (file)
@@ -22,15 +22,14 @@ package org.onap.policy.pap.main;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializer;
+import java.time.Instant;
 import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.gson.InstantTypeAdapter;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
 import org.springframework.context.annotation.Bean;
-import springfox.documentation.spring.web.json.Json;
 
 @SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
 @EntityScan(
@@ -50,9 +49,7 @@ public class PolicyPapApplication {
     @Bean
     public Gson gson() {
         GsonBuilder gsonBuilder = GsonMessageBodyHandler.configBuilder(new GsonBuilder());
-        JsonSerializer<Json> serializer =
-            (json, type, jsonSerializationContext) -> JsonParser.parseString(json.value());
-        gsonBuilder.registerTypeAdapter(Json.class, serializer);
+        gsonBuilder.registerTypeAdapter(Instant.class, new InstantTypeAdapter());
         return gsonBuilder.create();
     }
 }
diff --git a/main/src/main/java/org/onap/policy/pap/main/config/SpringDocBean.java b/main/src/main/java/org/onap/policy/pap/main/config/SpringDocBean.java
new file mode 100644 (file)
index 0000000..ab3dcf4
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021-2022 Nordix Foundation.
+ * ================================================================================
+ * 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.policy.pap.main.config;
+
+import io.swagger.v3.oas.models.ExternalDocumentation;
+import io.swagger.v3.oas.models.OpenAPI;
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.info.License;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class SpringDocBean {
+
+    /**
+     * Bean to configure Springdoc.
+     *
+     * @return the OpenAPI specification
+     */
+    @Bean
+    public OpenAPI policyFrameworkLifecycleOpenApi() {
+        return new OpenAPI()
+            .info(new Info().title("Policy Framework Policy Administration (PAP)")
+                .description(
+                    "The Policy Framework Policy Administration (PAP) allows"
+                        + " Policies to be grouped, deployed, and monitored")
+                .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0")))
+            .externalDocs(new ExternalDocumentation()
+                .description("Policy Framework Documentation")
+                .url("https://docs.onap.org/projects/onap-policy-parent/en/latest"));
+    }
+}
index fd4bb74..04971cc 100644 (file)
@@ -145,7 +145,7 @@ public abstract class CommonPapRestServer {
      */
     protected void testSwagger(final String endpoint) throws Exception {
         final Invocation.Builder invocationBuilder =
-                        sendFqeRequest(httpsPrefix + "v2/api-docs", true, MediaType.APPLICATION_JSON);
+                        sendFqeRequest(httpsPrefix + "v3/api-docs", true, MediaType.APPLICATION_JSON);
         final String resp = invocationBuilder.get(String.class);
         assertTrue(resp.contains(ENDPOINT_PREFIX + endpoint));
     }
index 1af9ff5..d1d29f0 100644 (file)
@@ -31,7 +31,6 @@ import javax.ws.rs.core.SecurityContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.springframework.http.ResponseEntity;
index 4800911..6762c49 100644 (file)
@@ -28,7 +28,6 @@ import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
 import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
-import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
 
 /**
index 8658b7d..23fa803 100644 (file)
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
-import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
 
 /**
index 0ed36d5..e19bdb8 100644 (file)
@@ -27,7 +27,6 @@ import javax.ws.rs.client.Invocation;
 import org.junit.Test;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.pap.main.PapConstants;
-import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
 
 /**