Skip to content

Allow Swagger UI CSS and JS paths to be configurable #2908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1254,6 +1255,19 @@ app.UseSwaggerUI(c =>
}
```

### Change CSS or JS Paths ###

By default, the Swagger UI inclide default CSS and JS, but if you need to change path or URL (ex 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.
Expand Down