This is an automated email from the ASF dual-hosted git repository. rzo1 pushed a commit to branch TOMEE-4344---MP6-OpenAPI-3.1 in repository https://gitbox.apache.org/repos/asf/tomee.git
commit c326b429829d11d0317e023bb05466a82e48a338 Author: Richard Zowalla <[email protected]> AuthorDate: Tue May 28 11:14:47 2024 +0200 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 - .../MicroProfileOpenAPITCKDeploymentPackager.java | 55 -------------------- .../MicroProfileOpenAPITCKExtension.java | 5 +- .../MicroProfileOpenAPITCKObserver.java | 2 +- .../MicroProfileOpenAPITCKProtocol.java | 27 ---------- .../MicroprofileOpenAPITCKDeploymentProcessor.java | 49 ++++++++++++++++++ .../openapi/src/test/resources/arquillian.xml | 3 -- .../openapi/MicroProfileOpenApiRegistration.java | 60 +++++++++++++--------- 15 files changed, 104 insertions(+), 132 deletions(-) diff --git a/boms/tomee-microprofile-api/pom.xml b/boms/tomee-microprofile-api/pom.xml index 6ef9f68d6b..26646ed14c 100644 --- a/boms/tomee-microprofile-api/pom.xml +++ b/boms/tomee-microprofile-api/pom.xml @@ -241,7 +241,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/boms/tomee-microprofile/pom.xml b/boms/tomee-microprofile/pom.xml index 78a0bf8170..09cf5e0eaf 100644 --- a/boms/tomee-microprofile/pom.xml +++ b/boms/tomee-microprofile/pom.xml @@ -433,7 +433,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>jandex</artifactId> - <version>3.0.1</version> + <version>3.1.6</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -510,7 +510,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-core</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -521,7 +521,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-jaxrs</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -2028,7 +2028,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/boms/tomee-plume-api/pom.xml b/boms/tomee-plume-api/pom.xml index 69b27d43b4..3ae9b28e15 100644 --- a/boms/tomee-plume-api/pom.xml +++ b/boms/tomee-plume-api/pom.xml @@ -241,7 +241,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/boms/tomee-plume/pom.xml b/boms/tomee-plume/pom.xml index 4e91de8cfe..dad08b36c4 100644 --- a/boms/tomee-plume/pom.xml +++ b/boms/tomee-plume/pom.xml @@ -433,7 +433,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>jandex</artifactId> - <version>3.0.1</version> + <version>3.1.6</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -510,7 +510,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-core</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -521,7 +521,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-jaxrs</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -2127,7 +2127,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/boms/tomee-plus-api/pom.xml b/boms/tomee-plus-api/pom.xml index 8ec544bc5b..53536ea538 100644 --- a/boms/tomee-plus-api/pom.xml +++ b/boms/tomee-plus-api/pom.xml @@ -252,7 +252,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/boms/tomee-plus/pom.xml b/boms/tomee-plus/pom.xml index fb31ce9341..ca59face48 100644 --- a/boms/tomee-plus/pom.xml +++ b/boms/tomee-plus/pom.xml @@ -433,7 +433,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>jandex</artifactId> - <version>3.0.1</version> + <version>3.1.6</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -510,7 +510,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-core</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -521,7 +521,7 @@ <dependency> <groupId>io.smallrye</groupId> <artifactId>smallrye-open-api-jaxrs</artifactId> - <version>3.0.1</version> + <version>3.10.0</version> <exclusions> <exclusion> <artifactId>*</artifactId> @@ -2149,7 +2149,7 @@ <dependency> <groupId>org.eclipse.microprofile.openapi</groupId> <artifactId>microprofile-openapi-api</artifactId> - <version>3.0</version> + <version>3.1.1</version> <exclusions> <exclusion> <artifactId>*</artifactId> diff --git a/pom.xml b/pom.xml index 23973ba828..89b7ce5d27 100644 --- a/pom.xml +++ b/pom.xml @@ -185,7 +185,7 @@ <version.microprofile.health>4.0.1</version.microprofile.health> <version.microprofile.jwt>2.1</version.microprofile.jwt> <version.microprofile.metrics>5.0.2</version.microprofile.metrics> - <version.microprofile.openapi>3.0</version.microprofile.openapi> + <version.microprofile.openapi>3.1.1</version.microprofile.openapi> <version.microprofile.opentracing>3.0</version.microprofile.opentracing> <version.microprofile.rest-client>3.0.1</version.microprofile.rest-client> @@ -196,7 +196,7 @@ <version.microprofile.impl.fault-tolerance>6.2.2</version.microprofile.impl.fault-tolerance> <version.microprofile.impl.health>4.0.1</version.microprofile.impl.health> <version.microprofile.impl.metrics>5.0.1</version.microprofile.impl.metrics> - <version.microprofile.impl.openapi>3.0.1</version.microprofile.impl.openapi> + <version.microprofile.impl.openapi>3.10.0</version.microprofile.impl.openapi> <version.microprofile.impl.opentracing>3.0.3</version.microprofile.impl.opentracing> <!-- Jackson and snakeyaml required by OpenAPI Impl --> diff --git a/tck/microprofile-tck/openapi/pom.xml b/tck/microprofile-tck/openapi/pom.xml index 1756f6e3d4..44e57ff88e 100644 --- a/tck/microprofile-tck/openapi/pom.xml +++ b/tck/microprofile-tck/openapi/pom.xml @@ -115,7 +115,6 @@ <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <!-- 7.4.0 is broken, so until 7.5.0 is released ... --> <version>7.5.1</version> <scope>test</scope> </dependency> 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 67c49a954b..0000000000 --- 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<ProtocolArchiveProcessor> 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<ArchivePath, Node> 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 8439fe5e3e..0c281eb0b6 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 db28c89961..ec323cd204 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 @@ import org.jboss.arquillian.core.api.annotation.Observes; 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 8d9a3c9d83..0000000000 --- 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 0000000000..5cbee1e646 --- /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 5fea36e73b..a5125a131d 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 @@ <property name="appWorkingDir">target/workdir</property> <property name="cleanOnStartUp">true</property> <property name="properties"> - geronimo.openapi.application.append-context-path = false </property> </configuration> </container> @@ -49,7 +48,6 @@ <property name="cleanOnStartUp">true</property> <property name="properties"> tomee.mp.scan = all - geronimo.openapi.application.append-context-path = false </property> </configuration> </container> @@ -65,7 +63,6 @@ <property name="cleanOnStartUp">true</property> <property name="properties"> tomee.mp.scan = all - geronimo.openapi.application.append-context-path = false </property> </configuration> </container> 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 8d70bbf84e..49b2e820b3 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 org.jboss.jandex.IndexView; 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.OpenApiProcessor.modelFromReader; 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 @@ import static java.util.Optional.ofNullable; 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<Class<?>> 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 @@ public class MicroProfileOpenApiRegistration implements ServletContainerInitiali Optional<OpenAPI> readerModel = ofNullable(modelFromReader(openApiConfig, contextClassLoader)); Optional<OpenAPI> staticFileModel = openApiFromStaticFile(servletContext); Optional<OpenAPI> annotationModel = - ofNullable(modelFromAnnotations(openApiConfig, contextClassLoader, filteredIndexView)); + ofNullable(modelFromAnnotations(openApiConfig, contextClassLoader, filteredIndexView)); final OpenApiDocument document = OpenApiDocument.INSTANCE; try { @@ -122,28 +129,29 @@ public class MicroProfileOpenApiRegistration implements ServletContainerInitiali private static OpenApiConfig config(final ServletContext servletContext) { try { final Optional<URL> 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 @@ public class MicroProfileOpenApiRegistration implements ServletContainerInitiali // look for static files already provided by the application final Optional<OpenAPI> 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 @@ public class MicroProfileOpenApiRegistration implements ServletContainerInitiali private static Optional<OpenAPI> 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 class MicroProfileOpenApiRegistration implements ServletContainerInitiali return (OpenAPI) servletContext.getAttribute(MicroProfileOpenApiRegistration.class.getName() + ".OpenAPI"); } + private static Map<String, String> getEnvProperties() { + return unmodifiableMap(doPrivileged((PrivilegedAction<Map<String, String>>) () -> new HashMap<>(System.getenv()))); + } + } \ No newline at end of file
