diff --git a/README.md b/README.md index 5a5ed3f42f..98d1c1c18b 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,7 @@ The steps described above will get you up and running with minimal setup. Howeve * [Swashbuckle.AspNetCore.SwaggerUI](#swashbuckleaspnetcoreswaggerui) * [Change Relative Path to the UI](#change-relative-path-to-the-ui) * [Change Document Title](#change-document-title) + * [Change CSS or JS Paths](#change-css-or-js-paths) * [List Multiple Swagger Documents](#list-multiple-swagger-documents) * [Apply swagger-ui Parameters](#apply-swagger-ui-parameters) * [Inject Custom JavaScript](#inject-custom-javascript) @@ -1254,6 +1255,19 @@ app.UseSwaggerUI(c => } ``` +### Change CSS or JS Paths ### + +By default, the Swagger UI include default CSS and JS, but if you wish to change the path or URL (for example to use a CDN): + +```csharp +app.UseSwaggerUI(c => +{ + c.StylesPath = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.10/swagger-ui.min.css"; + c.ScriptBundlePath = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.10/swagger-ui-bundle.min.js"; + c.ScriptPresetsPath = "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.17.10/swagger-ui-standalone-preset.min.js"; +} +``` + ### List Multiple Swagger Documents ### When enabling the middleware, you're required to specify one or more Swagger endpoints (fully qualified or relative to the UI page) to power the UI. If you provide multiple endpoints, they'll be listed in the top right corner of the page, allowing users to toggle between the different documents. For example, the following configuration could be used to document different versions of an API. diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs index 52dac4b73e..a8af5d0c13 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs @@ -163,6 +163,9 @@ private Dictionary GetIndexArguments() { { "%(DocumentTitle)", _options.DocumentTitle }, { "%(HeadContent)", _options.HeadContent }, + { "%(StylesPath)", _options.StylesPath }, + { "%(ScriptBundlePath)", _options.ScriptBundlePath }, + { "%(ScriptPresetsPath)", _options.ScriptPresetsPath }, { "%(ConfigObject)", configObject }, { "%(OAuthConfigObject)", oauthConfigObject }, { "%(Interceptors)", interceptors }, diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs index cd9aa9df42..bfb2a83534 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs @@ -50,6 +50,21 @@ public class SwaggerUIOptions /// Gets or sets the optional JSON serialization options to use to serialize options to the HTML document. /// public JsonSerializerOptions JsonSerializerOptions { get; set; } + + /// + /// Gets or sets the path or URL to the Swagger UI JavaScript bundle file. + /// + public string ScriptBundlePath { get; set; } = "./swagger-ui-bundle.js"; + + /// + /// Gets or sets the path or URL to the Swagger UI JavaScript standalone presets file. + /// + public string ScriptPresetsPath { get; set; } = "./swagger-ui-standalone-preset.js"; + + /// + /// Gets or sets the path or URL to the Swagger UI CSS file. + /// + public string StylesPath { get; set; } = "./swagger-ui.css"; } public class ConfigObject diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/index.html b/src/Swashbuckle.AspNetCore.SwaggerUI/index.html index c5360b2859..cfe58ed83e 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/index.html +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/index.html @@ -4,7 +4,7 @@ %(DocumentTitle) - +