diff options
author | liamfallon <liam.fallon@est.tech> | 2022-12-08 18:38:13 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2022-12-08 18:41:28 +0000 |
commit | 555445562f24224ac5333b32345adff62f2c0c4c (patch) | |
tree | 5fa5eccacf008639ae8d222453ee73c84624fba9 | |
parent | e5be0765d1f11dad136e4a81cf37bad481e26b0d (diff) |
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 <liam.fallon@est.tech>
-rw-r--r-- | main/pom.xml | 14 | ||||
-rw-r--r-- | main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java (renamed from main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java) | 35 | ||||
-rw-r--r-- | main/src/main/java/org/onap/policy/api/main/config/WebConfig.java | 23 |
3 files changed, 23 insertions, 49 deletions
diff --git a/main/pom.xml b/main/pom.xml index 588b59d9..5713c884 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -99,21 +99,15 @@ <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> 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/SpringDocBean.java index 052ae5c6..6c471928 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/SwaggerConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/SpringDocBean.java @@ -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. @@ -20,28 +20,29 @@ 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 +} 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<Json> serializer = - (json, type, jsonSerializationContext) -> JsonParser.parseString(json.value()); - gsonBuilder.registerTypeAdapter(Json.class, serializer); - return gsonBuilder.create(); - } -}
\ No newline at end of file +} |