Swagger.Bootstrap
2.0.2
dotnet add package Swagger.Bootstrap --version 2.0.2
NuGet\Install-Package Swagger.Bootstrap -Version 2.0.2
<PackageReference Include="Swagger.Bootstrap" Version="2.0.2" />
<PackageVersion Include="Swagger.Bootstrap" Version="2.0.2" />
<PackageReference Include="Swagger.Bootstrap" />
paket add Swagger.Bootstrap --version 2.0.2
#r "nuget: Swagger.Bootstrap, 2.0.2"
#:package Swagger.Bootstrap@2.0.2
#addin nuget:?package=Swagger.Bootstrap&version=2.0.2
#tool nuget:?package=Swagger.Bootstrap&version=2.0.2
<div align="center">
</div>
Swagger.Bootstrap
Swagger.Bootstrap is an add-on for Swagger UI that gives it a modern Bootstrap look and feel.
It also adds a simple theme switcher so users can toggle between Light, Dark, Oled and System.
✨ Features
- Bootstrap-inspired styling for Swagger UI
- Built-in theme switcher (light/dark)
- Navigation & Tool menus (Experimental)
- Authentication window, to authorize Swagger using JWT.
- Easy integration with ASP.NET Core Swagger setup
📂 Getting Started
1. NuGet package manager
Install using the NuGet package manager or by running one of the following commands.
dotnet add package Swagger.Bootstrap
Install-Package Swagger.Bootstrap
Version 2.X (NEW)
Version 2.X has returned to UseSwaggerBootstrap instead of UseSwaggerUI
In your Program.cs or Startup.cs, add the following methods.
builder.Services.AddSwaggerBootstrap();
Or
// All variables are optional.
builder.Services.AddSwaggerBootstrap(options =>
{
// Enables the experimental features,
// including navigation & tools.
options.UseExperimentalFeatures = true;
// Enables the login page and button.
options.UseAuthentication = true;
// The endpoint to call during login.
options.loginOptions.LoginEndpoint = "/auth/login";
// The variable to use for authentication, when login succeeds.
options.loginOptions.VariableName = "jwtToken";
// Whether to configure the username field as text or email.
// The label will be changed as well.
options.loginOptions.UserNameType = UserNameType.Text;
});
Then, replace the default UseSwaggerUI with:
app.UseSwaggerBootstrap(c =>
{
// OpenApi example, using swagger gen.
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
UseStaticFiles is no longer needed as the resources are dynamically mapped now.
Version 1.x
In your UseSwaggerUI just add AddSwaggerBootstrap:
app.UseSwaggerUI(options =>
{
options.AddSwaggerBootstrap();
});
To enable the experimental features, add AddExperimentalFeatures to AddSwaggerBootstrap:
options.AddSwaggerBootstrap()
.AddExperimentalFeatures();
This setup needs UseStaticFiles to be enabled:
app.UseStaticFiles();
PRE 1.0
Configure Swagger.Bootstrap
In your Program.cs or Startup.cs, simply replace the default UseSwaggerUI with:
app.UseSwaggerBootstrap(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
Or if you want to keep your existing SwaggerUI configuration:
(app.UseStaticFiles must be set)
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.AddSwaggerBootstrap();
});
app.UseStaticFiles();
2. Manual installation
Download the files
Copy the provided swagger.bootstrap.min.css and swagger.bootstrap.min.js files into your projects static file location, wwwroot.
Enable static files
Add the following, to your Program.cs or Startup.cs
app.UseStaticFiles();
Inject into Swagger UI
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
// Inject custom CSS
c.InjectStylesheet("/swagger.bootstrap.min.css");
// Inject custom JavaScript
c.InjectJavascript("/swagger.bootstrap.min.js");
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.19)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 9.0.4)
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.19)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 9.0.4)
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.19)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Swashbuckle.AspNetCore.SwaggerUI (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.