From 20fe535e2649e30ec8ffd367cbd7ba77a33774d6 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Tue, 21 Jan 2025 16:52:47 +1100 Subject: [PATCH] Enable new scripts config in Swagger UI Signed-off-by: Phillip Kruger --- .../io/quarkus/swaggerui/deployment/SwaggerUiConfig.java | 6 ++++++ .../quarkus/swaggerui/deployment/SwaggerUiProcessor.java | 5 +++++ .../quarkus/swaggerui/deployment/SwaggerOptionsTest.java | 8 ++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiConfig.java b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiConfig.java index af2ab9d5e29de..f85bf85527f5b 100644 --- a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiConfig.java +++ b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiConfig.java @@ -256,6 +256,12 @@ public class SwaggerUiConfig { @ConfigItem Optional> plugins; + /** + * A list of external scripts (usually plugins) to use in Swagger UI. + */ + @ConfigItem + Optional> scripts; + /** * A list of presets to use in Swagger UI. */ 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 662cad4ab3ff6..bc01164f7127e 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 @@ -348,6 +348,11 @@ private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, Swagg options.put(Option.plugins, plugins); } + if (swaggerUiConfig.scripts.isPresent()) { + String scripts = String.join(",", swaggerUiConfig.scripts.get()); + options.put(Option.scripts, scripts); + } + if (swaggerUiConfig.presets.isPresent()) { String presets = swaggerUiConfig.presets.get().toString(); options.put(Option.presets, presets); diff --git a/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/SwaggerOptionsTest.java b/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/SwaggerOptionsTest.java index 0b450d11d3f59..b9c4698f17a56 100644 --- a/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/SwaggerOptionsTest.java +++ b/extensions/swagger-ui/deployment/src/test/java/io/quarkus/swaggerui/deployment/SwaggerOptionsTest.java @@ -22,7 +22,7 @@ public class SwaggerOptionsTest { @Test public void customOptions() { - RestAssured.when().get("/q/swagger-ui").then().statusCode(200) + RestAssured.when().get("/q/swagger-ui").then().log().all().and().statusCode(200) .body( containsString("Testing title"), containsString("/openapi"), @@ -33,7 +33,9 @@ public void customOptions() { containsString("validatorUrl: 'localhost'"), containsString("displayRequestDuration: true"), containsString("supportedSubmitMethods: ['get', 'post']"), - containsString("plugins: [Plugin1, Plugin2]")); + containsString("plugins: [Plugin1, Plugin2]"), + containsString("https://unpkg.com/swagger-ui-plugin-hierarchical-tags"), + containsString("/some/local/script.js")); } @@ -61,5 +63,7 @@ private static String getPropertyAsString() { PROPERTIES.put("quarkus.swagger-ui.display-request-duration", "true"); PROPERTIES.put("quarkus.swagger-ui.supported-submit-methods", "get,post"); PROPERTIES.put("quarkus.swagger-ui.plugins", "Plugin1,Plugin2"); + PROPERTIES.put("quarkus.swagger-ui.scripts", + "https://unpkg.com/swagger-ui-plugin-hierarchical-tags,/some/local/script.js"); } }