diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java index 4e50a3ad5ace5a..3c927c2563aea9 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java @@ -67,6 +67,7 @@ import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; import io.quarkus.deployment.builditem.LaunchModeBuildItem; +import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; @@ -79,6 +80,7 @@ import io.quarkus.resteasy.server.common.spi.AllowedJaxRsAnnotationPrefixBuildItem; import io.quarkus.resteasy.server.common.spi.ResteasyJaxrsConfigBuildItem; import io.quarkus.runtime.LaunchMode; +import io.quarkus.runtime.configuration.ConfigBuilder; import io.quarkus.runtime.util.ClassPathUtils; import io.quarkus.security.Authenticated; import io.quarkus.smallrye.openapi.common.deployment.SmallRyeOpenApiConfig; @@ -89,6 +91,7 @@ import io.quarkus.smallrye.openapi.deployment.spi.AddToOpenAPIDefinitionBuildItem; import io.quarkus.smallrye.openapi.deployment.spi.IgnoreStaticDocumentBuildItem; import io.quarkus.smallrye.openapi.deployment.spi.OpenApiDocumentBuildItem; +import io.quarkus.smallrye.openapi.runtime.OpenApiConfigMapping; import io.quarkus.smallrye.openapi.runtime.OpenApiConstants; import io.quarkus.smallrye.openapi.runtime.OpenApiDocumentService; import io.quarkus.smallrye.openapi.runtime.OpenApiRecorder; @@ -103,6 +106,7 @@ import io.quarkus.vertx.http.deployment.RouteBuildItem; import io.quarkus.vertx.http.deployment.SecurityInformationBuildItem; import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem; +import io.smallrye.config.SmallRyeConfigBuilder; import io.smallrye.openapi.api.OpenApiConfig; import io.smallrye.openapi.api.OpenApiConfigImpl; import io.smallrye.openapi.api.OpenApiDocument; @@ -173,11 +177,15 @@ void contributeClassesToIndex(BuildProducer a @BuildStep void registerNativeImageResources(BuildProducer serviceProvider) { - // To map from smallrye and mp config to quarkus - serviceProvider.produce(ServiceProviderBuildItem.allProvidersFromClassPath(OpenApiConfigMapping.class.getName())); serviceProvider.produce(ServiceProviderBuildItem.allProvidersFromClassPath(OASFactoryResolver.class.getName())); } + @BuildStep + void runtimeOnly(BuildProducer runTimeConfigBuilder) { + // To map from smallrye and mp config to quarkus + runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(RuntimeOnlyBuilder.class.getName())); + } + @BuildStep void configFiles(BuildProducer watchedFiles, SmallRyeOpenApiConfig openApiConfig, @@ -1113,4 +1121,11 @@ private OASFilter filter(OpenApiConfig openApiConfig) { return OpenApiProcessor.getFilter(openApiConfig, Thread.currentThread().getContextClassLoader()); } + + public static class RuntimeOnlyBuilder implements ConfigBuilder { + @Override + public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) { + return builder.withInterceptors(new OpenApiConfigMapping()); + } + } } diff --git a/extensions/smallrye-openapi/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/extensions/smallrye-openapi/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor deleted file mode 100644 index aa926ba3f79c03..00000000000000 --- a/extensions/smallrye-openapi/deployment/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor +++ /dev/null @@ -1 +0,0 @@ -io.quarkus.smallrye.openapi.deployment.OpenApiConfigMapping diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/OpenApiConfigMapping.java b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiConfigMapping.java similarity index 99% rename from extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/OpenApiConfigMapping.java rename to extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiConfigMapping.java index d25441c5cd6114..cc788f25f18ec3 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/OpenApiConfigMapping.java +++ b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiConfigMapping.java @@ -1,4 +1,4 @@ -package io.quarkus.smallrye.openapi.deployment; +package io.quarkus.smallrye.openapi.runtime; import java.util.Collections; import java.util.HashMap; diff --git a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiDocumentService.java b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiDocumentService.java index 203c05353a85af..7b107646d0c33c 100644 --- a/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiDocumentService.java +++ b/extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiDocumentService.java @@ -5,11 +5,13 @@ import java.nio.charset.StandardCharsets; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.openapi.OASFilter; import org.eclipse.microprofile.openapi.models.OpenAPI; +import io.quarkus.runtime.ShutdownEvent; import io.smallrye.openapi.api.OpenApiConfig; import io.smallrye.openapi.api.OpenApiConfigImpl; import io.smallrye.openapi.api.OpenApiDocument; @@ -24,13 +26,16 @@ @ApplicationScoped public class OpenApiDocumentService implements OpenApiDocumentHolder { + private static final String OPENAPI_SERVERS = "mp.openapi.servers"; private final OpenApiDocumentHolder documentHolder; + private final String previousOpenApiServersSystemPropertyValue; public OpenApiDocumentService(OASFilter autoSecurityFilter, Config config) { String servers = config.getOptionalValue("quarkus.smallrye-openapi.servers", String.class).orElse(null); + this.previousOpenApiServersSystemPropertyValue = System.getProperty(OPENAPI_SERVERS); if (servers != null && !servers.isEmpty()) { - System.setProperty("mp.openapi.servers", servers); + System.setProperty(OPENAPI_SERVERS, servers); } if (config.getOptionalValue("quarkus.smallrye-openapi.always-run-filter", Boolean.class).orElse(Boolean.FALSE)) { @@ -40,6 +45,17 @@ public OpenApiDocumentService(OASFilter autoSecurityFilter, Config config) { } } + void reset(@Observes ShutdownEvent event) { + // Reset the value of the System property "mp.openapi.servers" to prevent side effects on tests since + // the value of System property "mp.openapi.servers" takes precedence over the value of + // "quarkus.smallrye-openapi.servers" due to the configuration mapping + if (previousOpenApiServersSystemPropertyValue == null) { + System.clearProperty(OPENAPI_SERVERS); + } else { + System.setProperty(OPENAPI_SERVERS, previousOpenApiServersSystemPropertyValue); + } + } + public byte[] getJsonDocument() { return this.documentHolder.getJsonDocument(); }