Skip to content

Commit

Permalink
Enable new scripts config in Swagger UI
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
(cherry picked from commit 20fe535)
  • Loading branch information
phillip-kruger authored and gsmet committed Jan 21, 2025
1 parent 3fcba30 commit cf9a219
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ public class SwaggerUiConfig {
@ConfigItem
Optional<List<String>> plugins;

/**
* A list of external scripts (usually plugins) to use in Swagger UI.
*/
@ConfigItem
Optional<List<String>> scripts;

/**
* A list of presets to use in Swagger UI.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"));

}

Expand Down Expand Up @@ -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");
}
}

0 comments on commit cf9a219

Please sign in to comment.