From c326b429829d11d0317e023bb05466a82e48a338 Mon Sep 17 00:00:00 2001 From: Richard Zowalla Date: Tue, 28 May 2024 11:14:47 +0200 Subject: [PATCH] TOMEE-4344 - MP6: OpenAPI 3.1 --- boms/tomee-microprofile-api/pom.xml | 2 +- boms/tomee-microprofile/pom.xml | 8 +-- boms/tomee-plume-api/pom.xml | 2 +- boms/tomee-plume/pom.xml | 8 +-- boms/tomee-plus-api/pom.xml | 2 +- boms/tomee-plus/pom.xml | 8 +-- pom.xml | 4 +- tck/microprofile-tck/openapi/pom.xml | 1 - ...roProfileOpenAPITCKDeploymentPackager.java | 55 ----------------- .../MicroProfileOpenAPITCKExtension.java | 5 +- .../MicroProfileOpenAPITCKObserver.java | 2 +- .../MicroProfileOpenAPITCKProtocol.java | 27 --------- ...oprofileOpenAPITCKDeploymentProcessor.java | 49 +++++++++++++++ .../openapi/src/test/resources/arquillian.xml | 3 - .../MicroProfileOpenApiRegistration.java | 60 +++++++++++-------- 15 files changed, 104 insertions(+), 132 deletions(-) delete mode 100644 tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKDeploymentPackager.java delete mode 100644 tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKProtocol.java create mode 100644 tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroprofileOpenAPITCKDeploymentProcessor.java diff --git a/boms/tomee-microprofile-api/pom.xml b/boms/tomee-microprofile-api/pom.xml index 6ef9f68d6b0..26646ed14c9 100644 --- a/boms/tomee-microprofile-api/pom.xml +++ b/boms/tomee-microprofile-api/pom.xml @@ -241,7 +241,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/boms/tomee-microprofile/pom.xml b/boms/tomee-microprofile/pom.xml index 78a0bf81707..09cf5e0eafd 100644 --- a/boms/tomee-microprofile/pom.xml +++ b/boms/tomee-microprofile/pom.xml @@ -433,7 +433,7 @@ io.smallrye jandex - 3.0.1 + 3.1.6 * @@ -510,7 +510,7 @@ io.smallrye smallrye-open-api-core - 3.0.1 + 3.10.0 * @@ -521,7 +521,7 @@ io.smallrye smallrye-open-api-jaxrs - 3.0.1 + 3.10.0 * @@ -2028,7 +2028,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/boms/tomee-plume-api/pom.xml b/boms/tomee-plume-api/pom.xml index 69b27d43b47..3ae9b28e15e 100644 --- a/boms/tomee-plume-api/pom.xml +++ b/boms/tomee-plume-api/pom.xml @@ -241,7 +241,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/boms/tomee-plume/pom.xml b/boms/tomee-plume/pom.xml index 4e91de8cfea..dad08b36c4b 100644 --- a/boms/tomee-plume/pom.xml +++ b/boms/tomee-plume/pom.xml @@ -433,7 +433,7 @@ io.smallrye jandex - 3.0.1 + 3.1.6 * @@ -510,7 +510,7 @@ io.smallrye smallrye-open-api-core - 3.0.1 + 3.10.0 * @@ -521,7 +521,7 @@ io.smallrye smallrye-open-api-jaxrs - 3.0.1 + 3.10.0 * @@ -2127,7 +2127,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/boms/tomee-plus-api/pom.xml b/boms/tomee-plus-api/pom.xml index 8ec544bc5b4..53536ea5383 100644 --- a/boms/tomee-plus-api/pom.xml +++ b/boms/tomee-plus-api/pom.xml @@ -252,7 +252,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/boms/tomee-plus/pom.xml b/boms/tomee-plus/pom.xml index fb31ce93415..ca59face484 100644 --- a/boms/tomee-plus/pom.xml +++ b/boms/tomee-plus/pom.xml @@ -433,7 +433,7 @@ io.smallrye jandex - 3.0.1 + 3.1.6 * @@ -510,7 +510,7 @@ io.smallrye smallrye-open-api-core - 3.0.1 + 3.10.0 * @@ -521,7 +521,7 @@ io.smallrye smallrye-open-api-jaxrs - 3.0.1 + 3.10.0 * @@ -2149,7 +2149,7 @@ org.eclipse.microprofile.openapi microprofile-openapi-api - 3.0 + 3.1.1 * diff --git a/pom.xml b/pom.xml index 23973ba828b..89b7ce5d27e 100644 --- a/pom.xml +++ b/pom.xml @@ -185,7 +185,7 @@ 4.0.1 2.1 5.0.2 - 3.0 + 3.1.1 3.0 3.0.1 @@ -196,7 +196,7 @@ 6.2.2 4.0.1 5.0.1 - 3.0.1 + 3.10.0 3.0.3 diff --git a/tck/microprofile-tck/openapi/pom.xml b/tck/microprofile-tck/openapi/pom.xml index 1756f6e3d42..44e57ff88e4 100644 --- a/tck/microprofile-tck/openapi/pom.xml +++ b/tck/microprofile-tck/openapi/pom.xml @@ -115,7 +115,6 @@ org.testng testng - 7.5.1 test diff --git a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKDeploymentPackager.java b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKDeploymentPackager.java deleted file mode 100644 index 67c49a954bb..00000000000 --- a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKDeploymentPackager.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.apache.tomee.microprofile.tck.openapi; - -import org.apache.ziplock.JarLocation; -import org.hamcrest.Matchers; -import org.jboss.arquillian.container.test.spi.TestDeployment; -import org.jboss.arquillian.container.test.spi.client.deployment.ProtocolArchiveProcessor; -import org.jboss.arquillian.protocol.servlet5.v_5.ServletProtocolDeploymentPackager; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ArchivePath; -import org.jboss.shrinkwrap.api.Node; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; - -import java.util.Collection; -import java.util.Map; - -public class MicroProfileOpenAPITCKDeploymentPackager extends ServletProtocolDeploymentPackager { - @Override - public Archive generateDeployment(final TestDeployment testDeployment, - final Collection processors) { - final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "microprofile-openapi.war") - .merge(testDeployment.getApplicationArchive()) - .addAsLibrary(JarLocation.jarLocation(Matchers.class)) // required for ModelConstructionTest - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - ; - - // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46. - if (testDeployment.getApplicationArchive() instanceof WebArchive) { - final Map content = - testDeployment.getApplicationArchive().getContent( - object -> object.get().matches(".*META-INF/.*")); - content.forEach((archivePath, node) -> webArchive.addAsResource(node.getAsset(), node.getPath())); - } - - return super.generateDeployment( - new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors); - } -} diff --git a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKExtension.java b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKExtension.java index 8439fe5e3e2..0c281eb0b6c 100644 --- a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKExtension.java +++ b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKExtension.java @@ -16,17 +16,14 @@ */ package org.apache.tomee.microprofile.tck.openapi; -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.container.test.spi.client.protocol.Protocol; import org.jboss.arquillian.core.spi.LoadableExtension; -import org.jboss.arquillian.protocol.servlet5.v_5.ServletProtocol; public class MicroProfileOpenAPITCKExtension implements LoadableExtension { @Override public void register(final ExtensionBuilder extensionBuilder) { extensionBuilder - .override(Protocol.class, ServletProtocol.class, MicroProfileOpenAPITCKProtocol.class) .observer(MicroProfileOpenAPITCKObserver.class) + .observer(MicroprofileOpenAPITCKDeploymentProcessor.class) ; } } diff --git a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKObserver.java b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKObserver.java index db28c89961f..ec323cd2049 100644 --- a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKObserver.java +++ b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKObserver.java @@ -22,6 +22,6 @@ public class MicroProfileOpenAPITCKObserver { public void AfterDeploy(@Observes final AfterDeploy afterDeploy) { - RestAssured.basePath = "microprofile-openapi"; + RestAssured.basePath = afterDeploy.getDeployment().getArchive().getName().replace(".war",""); } } diff --git a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKProtocol.java b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKProtocol.java deleted file mode 100644 index 8d9a3c9d83b..00000000000 --- a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroProfileOpenAPITCKProtocol.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.apache.tomee.microprofile.tck.openapi; - -import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentPackager; -import org.jboss.arquillian.protocol.servlet5.v_5.ServletProtocol; - -public class MicroProfileOpenAPITCKProtocol extends ServletProtocol { - @Override - public DeploymentPackager getPackager() { - return new MicroProfileOpenAPITCKDeploymentPackager(); - } -} diff --git a/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroprofileOpenAPITCKDeploymentProcessor.java b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroprofileOpenAPITCKDeploymentProcessor.java new file mode 100644 index 00000000000..5cbee1e6460 --- /dev/null +++ b/tck/microprofile-tck/openapi/src/test/java/org.apache.tomee.microprofile.tck.openapi/MicroprofileOpenAPITCKDeploymentProcessor.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.tomee.microprofile.tck.openapi; + +import java.util.Map; + +import org.apache.ziplock.JarLocation; +import org.hamcrest.Matchers; +import org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription; +import org.jboss.arquillian.container.spi.event.container.BeforeDeploy; +import org.jboss.arquillian.core.api.annotation.Observes; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +public class MicroprofileOpenAPITCKDeploymentProcessor { + + public void observeDeployment(@Observes final BeforeDeploy beforeDeploy) { + DeploymentDescription deployment = beforeDeploy.getDeployment(); + Archive testableArchive = deployment.getTestableArchive(); + if (testableArchive != null) { + process(testableArchive); + } else { + process(deployment.getArchive()); + } + } + + private void process(Archive archive) { + if (archive instanceof WebArchive webapp) { + webapp.addAsLibrary(JarLocation.jarLocation(Matchers.class)) // required for ModelConstructionTest + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + } + +} \ No newline at end of file diff --git a/tck/microprofile-tck/openapi/src/test/resources/arquillian.xml b/tck/microprofile-tck/openapi/src/test/resources/arquillian.xml index 5fea36e73bf..a5125a131d4 100644 --- a/tck/microprofile-tck/openapi/src/test/resources/arquillian.xml +++ b/tck/microprofile-tck/openapi/src/test/resources/arquillian.xml @@ -33,7 +33,6 @@ target/workdir true - geronimo.openapi.application.append-context-path = false @@ -49,7 +48,6 @@ true tomee.mp.scan = all - geronimo.openapi.application.append-context-path = false @@ -65,7 +63,6 @@ true tomee.mp.scan = all - geronimo.openapi.application.append-context-path = false diff --git a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/openapi/MicroProfileOpenApiRegistration.java b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/openapi/MicroProfileOpenApiRegistration.java index 8d70bbf84e6..49b2e820b3a 100644 --- a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/openapi/MicroProfileOpenApiRegistration.java +++ b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/openapi/MicroProfileOpenApiRegistration.java @@ -16,9 +16,11 @@ */ package org.apache.tomee.microprofile.openapi; +import io.smallrye.config.EnvConfigSource; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfigBuilder; +import io.smallrye.config.SysPropConfigSource; import io.smallrye.openapi.api.OpenApiConfig; import io.smallrye.openapi.api.OpenApiConfigImpl; import io.smallrye.openapi.api.OpenApiDocument; @@ -39,6 +41,9 @@ import java.io.IOException; import java.net.URL; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Properties; @@ -51,6 +56,8 @@ import static io.smallrye.openapi.runtime.io.Format.JSON; import static io.smallrye.openapi.runtime.io.Format.YAML; import static java.lang.Thread.currentThread; +import static java.security.AccessController.doPrivileged; +import static java.util.Collections.unmodifiableMap; import static java.util.Optional.ofNullable; /** @@ -66,14 +73,14 @@ public class MicroProfileOpenApiRegistration implements ServletContainerInitializer { private static final Logger LOGGER = - Logger.getInstance(LogCategory.MICROPROFILE, MicroProfileOpenApiRegistration.class); + Logger.getInstance(LogCategory.MICROPROFILE, MicroProfileOpenApiRegistration.class); @Override public void onStartup(final Set> c, final ServletContext servletContext) throws ServletException { LOGGER.info("Registering OpenAPI servlet on /openapi for application " + servletContext.getContextPath()); final ServletRegistration.Dynamic servletRegistration = - servletContext.addServlet("mp-openapi-servlet", MicroProfileOpenApiEndpoint.class); + servletContext.addServlet("mp-openapi-servlet", MicroProfileOpenApiEndpoint.class); servletRegistration.addMapping("/openapi/*"); } @@ -97,7 +104,7 @@ private static Optional generateOpenAPI(final ServletContext servletCon Optional readerModel = ofNullable(modelFromReader(openApiConfig, contextClassLoader)); Optional staticFileModel = openApiFromStaticFile(servletContext); Optional annotationModel = - ofNullable(modelFromAnnotations(openApiConfig, contextClassLoader, filteredIndexView)); + ofNullable(modelFromAnnotations(openApiConfig, contextClassLoader, filteredIndexView)); final OpenApiDocument document = OpenApiDocument.INSTANCE; try { @@ -122,28 +129,29 @@ private static Optional generateOpenAPI(final ServletContext servletCon private static OpenApiConfig config(final ServletContext servletContext) { try { final Optional microprofileConfig = - Stream.of(ofNullable(servletContext.getResource("/META-INF/microprofile-config.properties")), - ofNullable( - servletContext.getResource("/WEB-INF/classes/META-INF/microprofile-config.properties"))) - .filter(Optional::isPresent) - .findFirst() - .flatMap(url -> url); + Stream.of(ofNullable(servletContext.getResource("/META-INF/microprofile-config.properties")), + ofNullable( + servletContext.getResource("/WEB-INF/classes/META-INF/microprofile-config.properties"))) + .filter(Optional::isPresent) + .findFirst() + .flatMap(url -> url); if (microprofileConfig.isEmpty()) { LOGGER.debug( - "Could not find OpenAPI config from MicroProfile Config files. Using default configuration."); + "Could not find OpenAPI config from MicroProfile Config files. Using default configuration."); return new OpenApiConfigImpl(ConfigProvider.getConfig()); } LOGGER.debug( - "Building OpenAPI config from MicroProfile Config file " + microprofileConfig.get().toExternalForm()); + "Building OpenAPI config from MicroProfile Config file " + microprofileConfig.get().toExternalForm()); final Properties properties = IO.readProperties(microprofileConfig.get()); final SmallRyeConfig config = new SmallRyeConfigBuilder() - .addDefaultSources() - .addDefaultInterceptors() - .withSources(new PropertiesConfigSource(properties, "microprofile-config.properties")) - .build(); + .withSources(new EnvConfigSource(getEnvProperties(), 300)) + .withSources(new SysPropConfigSource()) + .withSources(new PropertiesConfigSource(properties, "microprofile-config.properties")) + .addDefaultInterceptors() + .build(); return new OpenApiConfigImpl(config); @@ -158,16 +166,16 @@ private static Optional openApiFromStaticFile(final ServletContext serv // look for static files already provided by the application final Optional staticOpenApi = Stream - .of(readOpenApiFile(servletContext, "/META-INF/openapi.json", JSON), - readOpenApiFile(servletContext, "/META-INF/openapi.yaml", YAML), - readOpenApiFile(servletContext, "/META-INF/openapi.yml", YAML)) - .filter(Optional::isPresent) - .findFirst() - .flatMap(file -> file); + .of(readOpenApiFile(servletContext, "/META-INF/openapi.json", JSON), + readOpenApiFile(servletContext, "/META-INF/openapi.yaml", YAML), + readOpenApiFile(servletContext, "/META-INF/openapi.yml", YAML)) + .filter(Optional::isPresent) + .findFirst() + .flatMap(file -> file); if (staticOpenApi.isEmpty()) { LOGGER.debug( - "Could not find any static OpenAPI file in application " + servletContext.getContextPath()); + "Could not find any static OpenAPI file in application " + servletContext.getContextPath()); } return staticOpenApi; @@ -180,8 +188,8 @@ private static Optional openApiFromStaticFile(final ServletContext serv private static Optional readOpenApiFile( - final ServletContext servletContext, final String location, - final Format format) throws Exception { + final ServletContext servletContext, final String location, + final Format format) throws Exception { final URL resource = servletContext.getResource(location); if (resource == null) { @@ -209,4 +217,8 @@ public static OpenAPI getOpenApi(final ServletContext servletContext) { return (OpenAPI) servletContext.getAttribute(MicroProfileOpenApiRegistration.class.getName() + ".OpenAPI"); } + private static Map getEnvProperties() { + return unmodifiableMap(doPrivileged((PrivilegedAction>) () -> new HashMap<>(System.getenv()))); + } + } \ No newline at end of file