From 35cdf9ccfc81c5e42d725766deb08e6d11e64326 Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 14:02:36 +0300 Subject: [PATCH 1/9] support swagger plugins --- README.md | 3 +++ .../PublicAPI/PublicAPI.Unshipped.txt | 2 ++ .../SwaggerUIOptions.cs | 7 +++++++ src/Swashbuckle.AspNetCore.SwaggerUI/index.js | 1 + test/WebSites/CustomUIConfig/Startup.cs | 5 +++-- .../CustomUIConfig/wwwroot/ext/custom-plugin.js | 11 +++++++++++ 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js diff --git a/README.md b/README.md index a384f71089..1ddc1fcbd4 100644 --- a/README.md +++ b/README.md @@ -1302,6 +1302,7 @@ app.UseSwaggerUI(c => c.MaxDisplayedTags(5); c.ShowExtensions(); c.ShowCommonExtensions(); + c.Plugins = new string[]{"myCustomPlugin"} c.EnableValidator(); c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Head); c.UseRequestInterceptor("(request) => { return request; }"); @@ -1309,6 +1310,8 @@ app.UseSwaggerUI(c => }); ``` +_NOTE: When adding custom plugins, make sure you added custom `js` file that defines the plugin function._ + ### Inject Custom JavaScript ### To tweak the behavior, you can inject additional JavaScript files by adding them to your `wwwroot` folder and specifying the relative paths in the middleware options: diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt index e69de29bb2..31ca1d9d45 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt @@ -0,0 +1,2 @@ +Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> string[] +Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.set -> void diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs index 8ca532b253..4a1cf32b85 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs @@ -190,6 +190,13 @@ public class ConfigObject [JsonPropertyName("validatorUrl")] public string ValidatorUrl { get; set; } = null; + + /// + /// Custom plugins function names. + /// + [JsonPropertyName("plugins")] + public string[] Plugins { get; set; } = null; + [JsonExtensionData] public Dictionary AdditionalItems { get; set; } = []; } diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js index 7c4e7c59ee..6584df1e30 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js @@ -57,6 +57,7 @@ window.onload = function () { if (interceptors.ResponseInterceptorFunction) configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction); + configObject.plugins = configObject.plugins ? configObject.plugins.map(eval) : []; // Begin Swagger UI call region const ui = SwaggerUIBundle(configObject); diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs index b954f5770e..37076d41ff 100644 --- a/test/WebSites/CustomUIConfig/Startup.cs +++ b/test/WebSites/CustomUIConfig/Startup.cs @@ -73,14 +73,15 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) // Other c.DocumentTitle = "CustomUIConfig"; c.StylesPath = "/ext/custom-stylesheet.css"; - c.ScriptBundlePath = "/ext/custom-javascript.js"; - c.ScriptPresetsPath = "/ext/custom-javascript.js"; c.InjectStylesheet("/ext/custom-stylesheet.css"); c.InjectJavascript("/ext/custom-javascript.js"); + c.InjectJavascript("/ext/custom-plugin.js"); c.UseRequestInterceptor("(req) => { req.headers['x-my-custom-header'] = 'MyCustomValue'; return req; }"); c.UseResponseInterceptor("(res) => { console.log('Custom interceptor intercepted response from:', res.url); return res; }"); c.EnablePersistAuthorization(); + c.ConfigObject.Plugins = new[] { "customPlugin" }; + c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false); c.ConfigObject.AdditionalItems.Add("charProperty", 'c'); c.ConfigObject.AdditionalItems.Add("stringProperty", "value"); diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js new file mode 100644 index 0000000000..73bcdc1d8b --- /dev/null +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js @@ -0,0 +1,11 @@ + +const customPlugin = function (system) { + var elem = document.createElement("div"); + elem.innerHTML = + "
This text was injected via /ext/custom-plugin.js, using the SwaggerUIOptions.Plugins method.
"; + + document.body.insertBefore(elem, document.body.firstChild); + return { + + } +} From af4b45290252a447d386ee1ba9ec77475d72fcf5 Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 15:35:06 +0300 Subject: [PATCH 2/9] review changes --- .../PublicAPI/PublicAPI.Unshipped.txt | 2 +- src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs | 5 ++--- src/Swashbuckle.AspNetCore.SwaggerUI/index.js | 4 +++- test/WebSites/CustomUIConfig/Startup.cs | 2 +- test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt index 31ca1d9d45..7d361b8837 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt @@ -1,2 +1,2 @@ -Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> string[] +Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> System.Collections.Generic.IList Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.set -> void diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs index 4a1cf32b85..09fc304abe 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs @@ -190,12 +190,11 @@ public class ConfigObject [JsonPropertyName("validatorUrl")] public string ValidatorUrl { get; set; } = null; - /// - /// Custom plugins function names. + /// Any custom plugins' function names. /// [JsonPropertyName("plugins")] - public string[] Plugins { get; set; } = null; + public IList Plugins { get; set; } = null; [JsonExtensionData] public Dictionary AdditionalItems { get; set; } = []; diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js index 6584df1e30..91603b814f 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js @@ -57,7 +57,9 @@ window.onload = function () { if (interceptors.ResponseInterceptorFunction) configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction); - configObject.plugins = configObject.plugins ? configObject.plugins.map(eval) : []; + if(configObject.plugins) { + configObject.plugins = configObject.plugins.map(eval); + } // Begin Swagger UI call region const ui = SwaggerUIBundle(configObject); diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs index 37076d41ff..43ba1f4feb 100644 --- a/test/WebSites/CustomUIConfig/Startup.cs +++ b/test/WebSites/CustomUIConfig/Startup.cs @@ -80,7 +80,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) c.UseResponseInterceptor("(res) => { console.log('Custom interceptor intercepted response from:', res.url); return res; }"); c.EnablePersistAuthorization(); - c.ConfigObject.Plugins = new[] { "customPlugin" }; + c.ConfigObject.Plugins = ["customPlugin"]; c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false); c.ConfigObject.AdditionalItems.Add("charProperty", 'c'); diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js index 73bcdc1d8b..51e6ae9660 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js @@ -6,6 +6,5 @@ const customPlugin = function (system) { document.body.insertBefore(elem, document.body.firstChild); return { - } } From 73cf0e84a38924120fcdb69eda6c79be41968831 Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 15:47:49 +0300 Subject: [PATCH 3/9] review changes --- README.md | 4 ++-- src/Swashbuckle.AspNetCore.SwaggerUI/index.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ddc1fcbd4..b7fe5f8bcc 100644 --- a/README.md +++ b/README.md @@ -1309,8 +1309,8 @@ app.UseSwaggerUI(c => c.UseResponseInterceptor("(response) => { return response; }"); }); ``` - -_NOTE: When adding custom plugins, make sure you added custom `js` file that defines the plugin function._ + [!NOTE] + When adding custom plugins, make sure you added custom `js` file that defines the plugin function. ### Inject Custom JavaScript ### diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js index 91603b814f..5f6bc23308 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js @@ -60,6 +60,7 @@ window.onload = function () { if(configObject.plugins) { configObject.plugins = configObject.plugins.map(eval); } + // Begin Swagger UI call region const ui = SwaggerUIBundle(configObject); From d42e50530e379aff946086a756344f1d80ed02ff Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 15:54:14 +0300 Subject: [PATCH 4/9] review changes --- README.md | 5 +++-- test/WebSites/CustomUIConfig/Startup.cs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7fe5f8bcc..2f29a267cc 100644 --- a/README.md +++ b/README.md @@ -1309,8 +1309,9 @@ app.UseSwaggerUI(c => c.UseResponseInterceptor("(response) => { return response; }"); }); ``` - [!NOTE] - When adding custom plugins, make sure you added custom `js` file that defines the plugin function. + + > [!NOTE] + > When adding custom plugins, make sure you added custom `js` file that defines the plugin function(s). ### Inject Custom JavaScript ### diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs index 43ba1f4feb..dcff4ea7ce 100644 --- a/test/WebSites/CustomUIConfig/Startup.cs +++ b/test/WebSites/CustomUIConfig/Startup.cs @@ -74,6 +74,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) c.DocumentTitle = "CustomUIConfig"; c.StylesPath = "/ext/custom-stylesheet.css"; c.InjectStylesheet("/ext/custom-stylesheet.css"); + c.ScriptBundlePath = "/ext/custom-javascript.js"; + c.ScriptPresetsPath = "/ext/custom-javascript.js"; c.InjectJavascript("/ext/custom-javascript.js"); c.InjectJavascript("/ext/custom-plugin.js"); c.UseRequestInterceptor("(req) => { req.headers['x-my-custom-header'] = 'MyCustomValue'; return req; }"); From 59f331cc38fa7ab7e9de36b3422c83d036be5dfe Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 16:15:51 +0300 Subject: [PATCH 5/9] tests --- .../SwaggerUIIntegrationTests.cs | 23 +++++++++++++++++++ test/WebSites/CustomUIConfig/Startup.cs | 5 ++-- .../{custom-plugin.js => custom-plugin1.js} | 6 ++--- .../wwwroot/ext/custom-plugin2.js | 10 ++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) rename test/WebSites/CustomUIConfig/wwwroot/ext/{custom-plugin.js => custom-plugin1.js} (69%) create mode 100644 test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs index fa52f555da..b3dc6e1d7a 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Net; using System.Threading.Tasks; using Xunit; @@ -74,6 +75,28 @@ public async Task SwaggerUIMiddleware_ReturnsInitializerScript( Assert.DoesNotContain("%(Interceptors)", jsContent); } + [Theory] + [InlineData(typeof(Basic.Startup), "/index.js", null)] + [InlineData(typeof(CustomUIConfig.Startup), "/swagger/index.js", "customPlugin1,customPlugin2")] + public async Task IndexUrl_DefinesPlugins_IfConfigured(Type startupType, string indexJsPath, string customPlugins) + { + var client = new TestSite(startupType).BuildClient(); + + var jsResponse = await client.GetAsync(indexJsPath); + Assert.Equal(HttpStatusCode.OK, jsResponse.StatusCode); + + var jsContent = await jsResponse.Content.ReadAsStringAsync(); + if (string.IsNullOrEmpty(customPlugins)) + { + Assert.DoesNotContain("\"plugins\"", jsContent); + } + else + { + string pluginsNames = string.Join(',', customPlugins.Split(',').Select(p => $"\"{p}\"")); + Assert.Contains($"\"plugins\":[{pluginsNames}]", jsContent); + } + } + [Fact] public async Task IndexUrl_ReturnsCustomPageTitleAndStylesheets_IfConfigured() { diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs index dcff4ea7ce..787591feb0 100644 --- a/test/WebSites/CustomUIConfig/Startup.cs +++ b/test/WebSites/CustomUIConfig/Startup.cs @@ -77,12 +77,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) c.ScriptBundlePath = "/ext/custom-javascript.js"; c.ScriptPresetsPath = "/ext/custom-javascript.js"; c.InjectJavascript("/ext/custom-javascript.js"); - c.InjectJavascript("/ext/custom-plugin.js"); + c.InjectJavascript("/ext/custom-plugin1.js"); + c.InjectJavascript("/ext/custom-plugin2.js"); c.UseRequestInterceptor("(req) => { req.headers['x-my-custom-header'] = 'MyCustomValue'; return req; }"); c.UseResponseInterceptor("(res) => { console.log('Custom interceptor intercepted response from:', res.url); return res; }"); c.EnablePersistAuthorization(); - c.ConfigObject.Plugins = ["customPlugin"]; + c.ConfigObject.Plugins = ["customPlugin1","customPlugin2"]; c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false); c.ConfigObject.AdditionalItems.Add("charProperty", 'c'); diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js similarity index 69% rename from test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js rename to test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js index 51e6ae9660..1c0ee09310 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js @@ -1,10 +1,10 @@ -const customPlugin = function (system) { +const customPlugin1 = function (system) { var elem = document.createElement("div"); elem.innerHTML = - "
This text was injected via /ext/custom-plugin.js, using the SwaggerUIOptions.Plugins method.
"; + "
This text was injected via /ext/custom-plugin1.js, using the SwaggerUIOptions.Plugins method.
"; document.body.insertBefore(elem, document.body.firstChild); return { - } + }; } diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js new file mode 100644 index 0000000000..3787c431b5 --- /dev/null +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js @@ -0,0 +1,10 @@ + +const customPlugin2 = function (system) { + var elem = document.createElement("div"); + elem.innerHTML = + "
This text was injected via /ext/custom-plugin2.js, using the SwaggerUIOptions.Plugins method.
"; + + document.body.insertBefore(elem, document.body.firstChild); + return { + }; +} From ecdda11bcbb59a32c0bc75ab95c82880c72dedf2 Mon Sep 17 00:00:00 2001 From: jvmlet Date: Thu, 29 Aug 2024 16:17:21 +0300 Subject: [PATCH 6/9] review changes --- README.md | 2 +- src/Swashbuckle.AspNetCore.SwaggerUI/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f29a267cc..02ddb13cef 100644 --- a/README.md +++ b/README.md @@ -1311,7 +1311,7 @@ app.UseSwaggerUI(c => ``` > [!NOTE] - > When adding custom plugins, make sure you added custom `js` file that defines the plugin function(s). + > When adding custom plugins, make sure you add any custom `js` files that define the plugin function(s). ### Inject Custom JavaScript ### diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js index 5f6bc23308..228274b1ab 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/index.js +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/index.js @@ -57,7 +57,7 @@ window.onload = function () { if (interceptors.ResponseInterceptorFunction) configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction); - if(configObject.plugins) { + if (configObject.plugins) { configObject.plugins = configObject.plugins.map(eval); } From 323bc5c8d2b620958473f49b39b69b4318dcda8f Mon Sep 17 00:00:00 2001 From: jvmlet Date: Sun, 1 Sep 2024 08:24:15 +0300 Subject: [PATCH 7/9] review fixes --- .../SwaggerUIIntegrationTests.cs | 31 ++++++++++--------- test/WebSites/CustomUIConfig/Startup.cs | 2 +- .../wwwroot/ext/custom-plugin1.js | 2 +- .../wwwroot/ext/custom-plugin2.js | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs index b3dc6e1d7a..512a4e78cc 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs @@ -75,26 +75,27 @@ public async Task SwaggerUIMiddleware_ReturnsInitializerScript( Assert.DoesNotContain("%(Interceptors)", jsContent); } - [Theory] - [InlineData(typeof(Basic.Startup), "/index.js", null)] - [InlineData(typeof(CustomUIConfig.Startup), "/swagger/index.js", "customPlugin1,customPlugin2")] - public async Task IndexUrl_DefinesPlugins_IfConfigured(Type startupType, string indexJsPath, string customPlugins) + [Fact] + public async Task IndexUrl_DefinesPlugins() { - var client = new TestSite(startupType).BuildClient(); + var client = new TestSite(typeof(CustomUIConfig.Startup)).BuildClient(); - var jsResponse = await client.GetAsync(indexJsPath); + var jsResponse = await client.GetAsync("/swagger/index.js"); Assert.Equal(HttpStatusCode.OK, jsResponse.StatusCode); var jsContent = await jsResponse.Content.ReadAsStringAsync(); - if (string.IsNullOrEmpty(customPlugins)) - { - Assert.DoesNotContain("\"plugins\"", jsContent); - } - else - { - string pluginsNames = string.Join(',', customPlugins.Split(',').Select(p => $"\"{p}\"")); - Assert.Contains($"\"plugins\":[{pluginsNames}]", jsContent); - } + Assert.Contains($"\"plugins\":[\"customPlugin1\",\"customPlugin2\"]", jsContent); + } + + [Fact] + public async Task IndexUrl_DoesntDefinePlugins() + { + var client = new TestSite(typeof(Basic.Startup)).BuildClient(); + + var jsResponse = await client.GetAsync("/index.js"); + Assert.Equal(HttpStatusCode.OK, jsResponse.StatusCode); + var jsContent = await jsResponse.Content.ReadAsStringAsync(); + Assert.DoesNotContain("\"plugins\"", jsContent); } [Fact] diff --git a/test/WebSites/CustomUIConfig/Startup.cs b/test/WebSites/CustomUIConfig/Startup.cs index 787591feb0..1ece2a2af1 100644 --- a/test/WebSites/CustomUIConfig/Startup.cs +++ b/test/WebSites/CustomUIConfig/Startup.cs @@ -83,7 +83,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) c.UseResponseInterceptor("(res) => { console.log('Custom interceptor intercepted response from:', res.url); return res; }"); c.EnablePersistAuthorization(); - c.ConfigObject.Plugins = ["customPlugin1","customPlugin2"]; + c.ConfigObject.Plugins = ["customPlugin1", "customPlugin2"]; c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false); c.ConfigObject.AdditionalItems.Add("charProperty", 'c'); diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js index 1c0ee09310..5aea1a0a53 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js @@ -7,4 +7,4 @@ const customPlugin1 = function (system) { document.body.insertBefore(elem, document.body.firstChild); return { }; -} +}; diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js index 3787c431b5..bbc18b9110 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js @@ -7,4 +7,4 @@ const customPlugin2 = function (system) { document.body.insertBefore(elem, document.body.firstChild); return { }; -} +}; From 126f4297aecb0f0453d32df8ac0d737e18ecbc37 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Sun, 1 Sep 2024 09:09:12 +0100 Subject: [PATCH 8/9] Apply suggestions from code review --- README.md | 2 +- .../SwaggerUIIntegrationTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02ddb13cef..057d59b784 100644 --- a/README.md +++ b/README.md @@ -1302,7 +1302,7 @@ app.UseSwaggerUI(c => c.MaxDisplayedTags(5); c.ShowExtensions(); c.ShowCommonExtensions(); - c.Plugins = new string[]{"myCustomPlugin"} + c.Plugins = ["myCustomPlugin"]; c.EnableValidator(); c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Head); c.UseRequestInterceptor("(request) => { return request; }"); diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs index 512a4e78cc..1a48cee80c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerUIIntegrationTests.cs @@ -84,7 +84,7 @@ public async Task IndexUrl_DefinesPlugins() Assert.Equal(HttpStatusCode.OK, jsResponse.StatusCode); var jsContent = await jsResponse.Content.ReadAsStringAsync(); - Assert.Contains($"\"plugins\":[\"customPlugin1\",\"customPlugin2\"]", jsContent); + Assert.Contains("\"plugins\":[\"customPlugin1\",\"customPlugin2\"]", jsContent); } [Fact] From b7b55d40219bddde96ce8849743d2cb3629ac2e5 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Sun, 1 Sep 2024 09:11:12 +0100 Subject: [PATCH 9/9] Apply suggestions from code review --- test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js | 1 - test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js | 1 - 2 files changed, 2 deletions(-) diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js index 5aea1a0a53..0e8988f106 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin1.js @@ -1,4 +1,3 @@ - const customPlugin1 = function (system) { var elem = document.createElement("div"); elem.innerHTML = diff --git a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js index bbc18b9110..b008e06570 100644 --- a/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js +++ b/test/WebSites/CustomUIConfig/wwwroot/ext/custom-plugin2.js @@ -1,4 +1,3 @@ - const customPlugin2 = function (system) { var elem = document.createElement("div"); elem.innerHTML =