diff --git a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java index a066920608573..c80976fc93b91 100644 --- a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java +++ b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java @@ -67,7 +67,7 @@ public class SwaggerUiProcessor { @BuildStep void feature(BuildProducer feature) { - if (launch.getLaunchMode().isDevOrTest() || swaggerUiConfig.alwaysInclude) { + if (swaggerUiConfig.enable && (launch.getLaunchMode().isDevOrTest() || swaggerUiConfig.alwaysInclude)) { feature.produce(new FeatureBuildItem(FeatureBuildItem.SWAGGER_UI)); } } @@ -88,6 +88,10 @@ public void registerSwaggerUiServletExtension(SwaggerUiRecorder recorder, "quarkus.swagger-ui.path was set to \"/\", this is not allowed as it blocks the application from serving anything else."); } + if (!swaggerUiConfig.enable) { + return; + } + String openApiPath = httpRootPathBuildItem.adjustPath(openapi.path); if (launch.getLaunchMode().isDevOrTest()) { CachedSwaggerUI cached = liveReloadBuildItem.getContextObject(CachedSwaggerUI.class); @@ -217,6 +221,12 @@ static final class SwaggerUiConfig { */ @ConfigItem(defaultValue = "false") boolean alwaysInclude; + + /** + * If Swagger UI should be enabled. By default, Swagger UI is enabled. + */ + @ConfigItem(defaultValue = "true") + boolean enable; } private static final class CachedSwaggerUI implements Runnable { diff --git a/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/DisabledTest.java b/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/DisabledTest.java new file mode 100644 index 0000000000000..0bbb66d34e410 --- /dev/null +++ b/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/DisabledTest.java @@ -0,0 +1,24 @@ +package io.quarkus.swaggerui.deployment; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class DisabledTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(new StringAsset("quarkus.swagger-ui.enable=false"), "application.properties")); + + @Test + public void shouldUseDefaultConfig() { + RestAssured.when().get("/swagger-ui").then().statusCode(404); + RestAssured.when().get("/swagger-ui/index.html").then().statusCode(404); + } +}