From ef2f847a68e9fedee844a6553da8fe8cbd6b3a79 Mon Sep 17 00:00:00 2001 From: Bruno Lellis Date: Mon, 9 Oct 2023 19:31:32 -0300 Subject: [PATCH] expose Swagger configuration tryItOutEnabled property (#1606) --- .../io/smallrye/openapi/ui/IndexHtmlCreator.java | 1 + .../main/java/io/smallrye/openapi/ui/Option.java | 1 + .../src/main/resources/template/index.html | 1 + .../io/smallrye/openapi/ui/IndexCreatorTest.java | 15 ++++++++++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/IndexHtmlCreator.java b/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/IndexHtmlCreator.java index 3cd8768a3..da228ca06 100644 --- a/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/IndexHtmlCreator.java +++ b/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/IndexHtmlCreator.java @@ -317,6 +317,7 @@ private static void addUrlSection(Map urls, String urlsPrimaryNa DEFAULT_OPTIONS.put(Option.onComplete, null); DEFAULT_OPTIONS.put(Option.syntaxHighlight, null); DEFAULT_OPTIONS.put(Option.queryConfigEnabled, null); + DEFAULT_OPTIONS.put(Option.tryItOutEnabled, null); // Network section DEFAULT_OPTIONS.put(Option.oauth2RedirectUrl, null); diff --git a/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/Option.java b/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/Option.java index 1f2c16f2a..11d6aefa0 100644 --- a/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/Option.java +++ b/ui/open-api-ui/src/main/java/io/smallrye/openapi/ui/Option.java @@ -45,6 +45,7 @@ public enum Option { layout, plugins, presets, + tryItOutEnabled, // OAuth related initOAuthSection, oauthClientId, diff --git a/ui/open-api-ui/src/main/resources/template/index.html b/ui/open-api-ui/src/main/resources/template/index.html index b51501275..9839c48a1 100644 --- a/ui/open-api-ui/src/main/resources/template/index.html +++ b/ui/open-api-ui/src/main/resources/template/index.html @@ -47,6 +47,7 @@ tagsSorter: ${tagsSorter}, onComplete: ${onComplete}, syntaxHighlight: ${syntaxHighlight}, + tryItOutEnabled: ${tryItOutEnabled}, requestInterceptor: ${requestInterceptor}, request.curlOptions: ${requestCurlOptions}, responseInterceptor: ${responseInterceptor}, diff --git a/ui/open-api-ui/src/test/java/io/smallrye/openapi/ui/IndexCreatorTest.java b/ui/open-api-ui/src/test/java/io/smallrye/openapi/ui/IndexCreatorTest.java index 2afce5350..153c9d99c 100644 --- a/ui/open-api-ui/src/test/java/io/smallrye/openapi/ui/IndexCreatorTest.java +++ b/ui/open-api-ui/src/test/java/io/smallrye/openapi/ui/IndexCreatorTest.java @@ -32,7 +32,7 @@ void testCreateDefault() throws IOException { assertTrue(s.contains("dom_id: '#swagger-ui',")); assertTrue(s.contains("deepLinking: true,")); assertFalse(s.contains("queryConfigEnabled")); - + assertFalse(s.contains("tryItOutEnabled")); } @Test @@ -240,4 +240,17 @@ void testCreateWithSyntaxHighlightObject() throws IOException { assertTrue(s.contains("syntaxHighlight: { activated: true, theme: \"monokai\" },")); } + + @Test + void testCreateWithTryItOutEnabledBoolean() throws IOException { + Map options = new HashMap<>(); + options.put(Option.tryItOutEnabled, "true"); + + byte[] indexHtml = IndexHtmlCreator.createIndexHtml(options); + assertNotNull(indexHtml); + + String s = new String(indexHtml); + + assertTrue(s.contains("tryItOutEnabled: true,")); + } }