diff options
author | Max Benjamin <max.benjamin@att.com> | 2021-03-17 16:35:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-03-17 16:35:06 +0000 |
commit | 10add89694eb04da38e80fd6eb26c369149570ec (patch) | |
tree | 008696053638e02ea538a22fc6b5a5fd08a07652 /asdc-controller/src | |
parent | b3b5dec2801b3eb4951e3e071490e240c8629a7a (diff) | |
parent | 8b98eb93f7b0c4dc1885a70db3ea8dd7bb84cc77 (diff) |
Merge "update swagger to v3 open api version"
Diffstat (limited to 'asdc-controller/src')
-rw-r--r-- | asdc-controller/src/main/java/org/onap/so/asdc/JerseyConfiguration.java | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/JerseyConfiguration.java b/asdc-controller/src/main/java/org/onap/so/asdc/JerseyConfiguration.java index 22265a0cc6..9929262dbc 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/JerseyConfiguration.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/JerseyConfiguration.java @@ -20,41 +20,51 @@ package org.onap.so.asdc; +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; import org.onap.so.asdc.client.test.rest.ASDCRestInterface; -import org.springframework.beans.factory.annotation.Autowired; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; +import io.swagger.v3.jaxrs2.SwaggerSerializers; +import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder; +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("/test") public class JerseyConfiguration extends ResourceConfig { - private Environment environment; - - @Autowired - public JerseyConfiguration(final Environment environment) { - this.environment = environment; - } + private static final Logger logger = LoggerFactory.getLogger(JerseyConfiguration.class); @PostConstruct public void setUp() { register(ASDCRestInterface.class); - register(ApiListingResource.class); + register(OpenApiResource.class); register(SwaggerSerializers.class); - final BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.2"); - beanConfig.setSchemes(new String[] {"http"}); - beanConfig.setHost("localhost:" + environment.getProperty("server.port")); - beanConfig.setBasePath("/mso"); - beanConfig.setResourcePackage("org.onap.so.apihandlerinfra"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); + final OpenAPI openApi = new OpenAPI(); + Info info = new Info(); + info.setVersion("1.0.2"); + info.setTitle("Swagger asdc-controller code"); + openApi.setInfo(info); + + SwaggerConfiguration swaggerConfig = new SwaggerConfiguration().openAPI(openApi).prettyPrint(true) + .resourcePackages(Stream.of("org.onap.so.asdc").collect(Collectors.toSet())); + + try { + JaxrsOpenApiContextBuilder jaxrsConfig = new JaxrsOpenApiContextBuilder(); + jaxrsConfig.application(this).openApiConfiguration(swaggerConfig).buildContext(true); + } catch (OpenApiConfigurationException e) { + logger.error("Error during jersey configuration", e); + throw new RuntimeException(e.getMessage(), e); + } + } } |