From ba997d7d6400f00fad424053df794e4ea9debb31 Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Wed, 11 Sep 2019 15:13:04 +0900 Subject: Upgrade swagger in mso-catalog-db-adapter Issue-ID: SO-2305 Change-Id: I25ac20a96cf44a7c8abaa3b78f3b256cb2002d3f Signed-off-by: arindamm --- adapters/mso-catalog-db-adapter/pom.xml | 19 +++++++++-- .../so/adapters/catalogdb/JerseyConfiguration.java | 37 +++++++++++++++------- .../adapters/catalogdb/rest/ServiceRestImpl.java | 23 +++++++++----- .../so/adapters/catalogdb/rest/VnfRestImpl.java | 18 ++++++++--- 4 files changed, 69 insertions(+), 28 deletions(-) (limited to 'adapters') diff --git a/adapters/mso-catalog-db-adapter/pom.xml b/adapters/mso-catalog-db-adapter/pom.xml index 9ec98cf96c..a51aa66afa 100644 --- a/adapters/mso-catalog-db-adapter/pom.xml +++ b/adapters/mso-catalog-db-adapter/pom.xml @@ -14,6 +14,7 @@ UTF-8 UTF-8 1.8 + 2.0.8 @@ -143,10 +144,22 @@ org.springframework.boot spring-boot-starter-web + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.9.9 + + + + io.swagger.core.v3 + swagger-annotations + ${swagger.version} + - io.swagger - swagger-jersey2-jaxrs - 1.5.16 + io.swagger.core.v3 + swagger-jaxrs2 + 2.0.6 org.mariadb.jdbc diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java index 699347015b..359c8cd46e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java @@ -20,6 +20,8 @@ package org.onap.so.adapters.catalogdb; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.PostConstruct; import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.server.ResourceConfig; @@ -30,9 +32,13 @@ import org.onap.so.adapters.catalogdb.rest.ServiceRestImpl; import org.onap.so.adapters.catalogdb.rest.VnfRestImpl; import org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter; import org.springframework.context.annotation.Configuration; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; +import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder; +import io.swagger.v3.jaxrs2.integration.resources.AcceptHeaderOpenApiResource; +import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource; +import io.swagger.v3.oas.integration.OpenApiConfigurationException; +import io.swagger.v3.oas.integration.SwaggerConfiguration; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; @Configuration @ApplicationPath("/ecomp/mso/catalog") @@ -42,18 +48,25 @@ public class JerseyConfiguration extends ResourceConfig { public void setUp() { System.setProperty(Constants.Property.PARTNER_NAME, ONAPComponents.CATALOG_DB.toString()); register(CatalogDbAdapterRest.class); - register(ApiListingResource.class); - register(SwaggerSerializers.class); register(SOAuditLogContainerFilter.class); + register(OpenApiResource.class); + register(AcceptHeaderOpenApiResource.class); register(ServiceRestImpl.class); register(VnfRestImpl.class); - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.2"); - beanConfig.setSchemes(new String[] {"https"}); - beanConfig.setBasePath("/ecomp/mso/catalog"); - beanConfig.setResourcePackage("org.onap.so.adapters.catalogdb.rest"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); + + OpenAPI oas = new OpenAPI(); + Info info = new Info(); + info.title("Swagger catalog-db-adapter bootstrap code"); + info.setVersion("1.0.2"); + + SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas).prettyPrint(true) + .resourcePackages(Stream.of("org.onap.so.adapters.catalogdb.rest").collect(Collectors.toSet())); + + try { + new JaxrsOpenApiContextBuilder().application(this).openApiConfiguration(oasConfig).buildContext(true); + } catch (OpenApiConfigurationException e) { + throw new RuntimeException(e.getMessage(), e); + } } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java index 6f556edfa1..bc4d0064d0 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java @@ -34,11 +34,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.google.common.base.Strings; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; -@Api(value = "/v1", tags = "model") + +@OpenAPIDefinition(info = @Info(title = "/v1", description = "model")) @Path("/v1/services") @Component public class ServiceRestImpl { @@ -63,14 +69,15 @@ public class ServiceRestImpl { } @GET - @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List") + @Operation(description = "Find Service Models", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class))))) @Produces({MediaType.APPLICATION_JSON}) @Transactional(readOnly = true) public List queryServices( - @ApiParam(value = "modelName", required = false) @QueryParam("modelName") String modelName, - @ApiParam(value = "distributionStatus", + @Parameter(description = "modelName", required = false) @QueryParam("modelName") String modelName, + @Parameter(description = "distributionStatus", required = false) @QueryParam("distributionStatus") String distributionStatus, - @ApiParam(value = "depth", required = false) @QueryParam("depth") int depth) { + @Parameter(description = "depth", required = false) @QueryParam("depth") int depth) { List services = new ArrayList<>(); List serviceFromDB = new ArrayList<>(); if (!Strings.isNullOrEmpty(modelName) && !Strings.isNullOrEmpty(distributionStatus)) { diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java index a3e3a8ee53..9202fd21d4 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java @@ -34,14 +34,20 @@ import javax.ws.rs.core.Response; import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository; +import org.onap.so.rest.catalog.beans.Service; import org.onap.so.rest.catalog.beans.Vnf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; -@Api(value = "/v1/services/{modelUUID}/vnfs", tags = "model") +@OpenAPIDefinition(info = @Info(title = "/v1/services/{modelUUID}/vnfs", description = "model")) @Path("/v1/services/{modelUUID}/vnfs") @Component public class VnfRestImpl { @@ -59,7 +65,8 @@ public class VnfRestImpl { private VnfCustomizationRepository vnfCustRepo; @GET - @ApiOperation(value = "Find a VNF model contained within a service", response = Vnf.class) + @Operation(description = "Find a VNF model contained within a service", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Vnf.class))))) @Path("/{modelCustomizationUUID}") @Produces({MediaType.APPLICATION_JSON}) @Transactional(readOnly = true) @@ -82,7 +89,8 @@ public class VnfRestImpl { } @PUT - @ApiOperation(value = "Update a VNF model contained within a service", response = Vnf.class) + @Operation(description = "Update a VNF model contained within a service", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Vnf.class))))) @Path("/{modelCustomizationUUID}") @Produces({MediaType.APPLICATION_JSON}) @Transactional -- cgit 1.2.3-korg