SwaggerUI.OpenApi
2.0.0
dotnet add package SwaggerUI.OpenApi --version 2.0.0
NuGet\Install-Package SwaggerUI.OpenApi -Version 2.0.0
<PackageReference Include="SwaggerUI.OpenApi" Version="2.0.0" />
<PackageVersion Include="SwaggerUI.OpenApi" Version="2.0.0" />
<PackageReference Include="SwaggerUI.OpenApi" />
paket add SwaggerUI.OpenApi --version 2.0.0
#r "nuget: SwaggerUI.OpenApi, 2.0.0"
#addin nuget:?package=SwaggerUI.OpenApi&version=2.0.0
#tool nuget:?package=SwaggerUI.OpenApi&version=2.0.0
SwaggerUI.OpenApi
A package to simplify adding Swagger UI to .NET 9's Microsoft.AspNetCore.OpenApi.
Usage
In your
Program.cs
file Addapp.AddSwaggerUI()
andapp.MapSwaggerUI()
:builder.Services.AddOpenApi(); + builder.Services.AddSwaggerUI(); var app = builder.Build(); app.MapOpenApi(); + app.MapSwaggerUI();
(Optional) Modify your
launchSettings.json
file to open Swagger automatically:- "launchBrowser": false, + "launchBrowser": true, "applicationUrl": "http://localhost:5150", + "launchUrl": "swagger",
Features
Authentication
If you want to add authentication to your Swagger you can use the following helper methods:
builder.Services.AddOpenApi("v1", o =>
{
o.AddOAuth2(authorizationUrl, tokenUrl, scopes);
});
builder.Services.AddSwaggerUI("v1", o =>
{
o.AddOAuth2(clientId, scopes);
});
There are other helper methods for Duende Identity Server AddIdentityServer()
and Auth0 AddAuth0
.
You can check the samples directory for complete working examples.
More snippet
Adds PowerShell and CMD cURL to the request snippet by default
Styles
Easily change syntax highlighting style
builder.Services.AddSwaggerUI(o =>
{
o.SyntaxHighlight = new SyntaxHighlightOptions
{
Theme = SyntaxHighlightThemeType.Arta
};
});
Parameter validation
Displays the common validations in the parameters form by default
app.MapGet("/products",
([Range(0, 10000)] int id,
[MinLength(3)][MaxLength(50)] string name,
[RegularExpression("\\d\\d-\\d\\d")] string code) => id)
Authorization persistence
Persists authorization data by default and it would not be lost on browser close or refresh so you don't have to authenticate everytime.
Roadmap
✅ Basic UI
✅ Authentication
✅ Enable all the documents
✅ Implement all Swagger UI options
⏳ Improve test coverage
Acknowledgement
This project is based on Swashbuckle.AspNetCore.SwaggerUI. Thanks for their awesome work.
Pre-release builds
Get the package from here.
Build
Install the required .NET SDK and run:
$ dotnet build
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net9.0
- Microsoft.AspNetCore.OpenApi (>= 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.