From 555445562f24224ac5333b32345adff62f2c0c4c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 8 Dec 2022 18:38:13 +0000 Subject: Replace SpringFox with SpringDoc in policy-api 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 --- main/pom.xml | 14 ++----- .../onap/policy/api/main/config/SpringDocBean.java | 48 ++++++++++++++++++++++ .../onap/policy/api/main/config/SwaggerConfig.java | 47 --------------------- .../org/onap/policy/api/main/config/WebConfig.java | 23 +---------- 4 files changed, 53 insertions(+), 79 deletions(-) create mode 100644 main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java delete mode 100644 main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java diff --git a/main/pom.xml b/main/pom.xml index 588b59d9..5713c884 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -98,22 +98,16 @@ org.springframework.boot spring-boot-starter-data-jpa + + org.springdoc + springdoc-openapi-ui + io.micrometer micrometer-registry-prometheus ${version.io.micrometer} runtime - - io.springfox - springfox-boot-starter - ${version.springfox} - - - io.springfox - springfox-swagger-ui - runtime - diff --git a/main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java b/main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java new file mode 100644 index 00000000..6c471928 --- /dev/null +++ b/main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java @@ -0,0 +1,48 @@ +/*- + * ============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.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; + +@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 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")); + } +} diff --git a/main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java b/main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java deleted file mode 100644 index 052ae5c6..00000000 --- a/main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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.policy.api.main.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; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class SwaggerConfig { - - /** - * Create a bean of type Docket to determine the swagger configuration. - * @return docket bean with swagger configuration. - */ - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage("org.onap.policy.api.main.rest")) - .paths(PathSelectors.any()) - .build(); - } -} \ No newline at end of file diff --git a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java index 80477b2e..ffc0edfd 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java @@ -20,21 +20,15 @@ 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 serializer = - (json, type, jsonSerializationContext) -> JsonParser.parseString(json.value()); - gsonBuilder.registerTypeAdapter(Json.class, serializer); - return gsonBuilder.create(); - } -} \ No newline at end of file +} -- cgit 1.2.3-korg