Replace SpringFox with SpringDoc in policy-api 43/132643/1
authorliamfallon <liam.fallon@est.tech>
Thu, 8 Dec 2022 18:38:13 +0000 (18:38 +0000)
committerliamfallon <liam.fallon@est.tech>
Thu, 8 Dec 2022 18:41:28 +0000 (18:41 +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: I5fb62e104c3a77e167a722a83f62dbddf2abedf1
Signed-off-by: liamfallon <liam.fallon@est.tech>
main/pom.xml
main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java [moved from main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java with 53% similarity]
main/src/main/java/org/onap/policy/api/main/config/WebConfig.java

index 588b59d..5713c88 100644 (file)
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-ui</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.micrometer</groupId>
             <artifactId>micrometer-registry-prometheus</artifactId>
             <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>
     </dependencies>
 
     <build>
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  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.
 
 package org.onap.policy.api.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;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 @Configuration
-@EnableSwagger2
-public class SwaggerConfig {
+public class SpringDocBean {
 
     /**
-     * Create a bean of type Docket to determine the swagger configuration.
-     * @return docket bean with swagger configuration.
+     * Bean to configure Springdoc.
+     *
+     * @return the OpenAPI specification
      */
     @Bean
-    public Docket api() {
-        return new Docket(DocumentationType.SWAGGER_2)
-            .select()
-            .apis(RequestHandlerSelectors.basePackage("org.onap.policy.api.main.rest"))
-            .paths(PathSelectors.any())
-            .build();
+    public OpenAPI policyFrameworkLifecycleOpenApi() {
+        return new OpenAPI()
+                .info(new Info().title("Policy Framework Lifecycle API")
+                .description("The Policy Framework API allows the lifecycle of policy types and policies to be managed")
+                .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"));
     }
-}
\ No newline at end of file
+}
index 80477b2..ffc0edf 100644 (file)
 
 package org.onap.policy.api.main.config;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializer;
 import java.util.Arrays;
 import java.util.List;
 import org.onap.policy.api.main.config.converter.StringToEnumConverter;
 import org.onap.policy.common.spring.utils.YamlHttpMessageConverter;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.format.FormatterRegistry;
 import org.springframework.http.MediaType;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import springfox.documentation.spring.web.json.Json;
 
 /**
  * Register custom converters to Spring configuration.
@@ -52,19 +46,4 @@ public class WebConfig implements WebMvcConfigurer {
         yamlConverter.setSupportedMediaTypes(Arrays.asList(MediaType.parseMediaType("application/yaml")));
         converters.add(yamlConverter);
     }
-
-    /**
-     * Swagger uses {{@link springfox.documentation.spring.web.json.Json}} which leads to Gson serialization errors.
-     * Hence, we customize a typeAdapter on the Gson bean.
-     *
-     * @return customised GSON instance.
-     */
-    @Bean
-    public Gson gson() {
-        GsonBuilder gsonBuilder = new GsonBuilder();
-        JsonSerializer<Json> serializer =
-            (json, type, jsonSerializationContext) -> JsonParser.parseString(json.value());
-        gsonBuilder.registerTypeAdapter(Json.class, serializer);
-        return gsonBuilder.create();
-    }
-}
\ No newline at end of file
+}