Skip to content

Commit

Permalink
Add ability to disable Swagger UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyb678 committed Jan 9, 2020
1 parent 11c2016 commit c26010e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SwaggerUiProcessor {

@BuildStep
void feature(BuildProducer<FeatureBuildItem> feature) {
if (launch.getLaunchMode().isDevOrTest() || swaggerUiConfig.alwaysInclude) {
if (swaggerUiConfig.enable && (launch.getLaunchMode().isDevOrTest() || swaggerUiConfig.alwaysInclude)) {
feature.produce(new FeatureBuildItem(FeatureBuildItem.SWAGGER_UI));
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit c26010e

Please sign in to comment.