Anarchy.Toolkit.Runtime.Web.Swagger 1.0.0

dotnet add package Anarchy.Toolkit.Runtime.Web.Swagger --version 1.0.0
                    
NuGet\Install-Package Anarchy.Toolkit.Runtime.Web.Swagger -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Anarchy.Toolkit.Runtime.Web.Swagger" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anarchy.Toolkit.Runtime.Web.Swagger" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Anarchy.Toolkit.Runtime.Web.Swagger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Anarchy.Toolkit.Runtime.Web.Swagger --version 1.0.0
                    
#r "nuget: Anarchy.Toolkit.Runtime.Web.Swagger, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Anarchy.Toolkit.Runtime.Web.Swagger@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Anarchy.Toolkit.Runtime.Web.Swagger&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Anarchy.Toolkit.Runtime.Web.Swagger&version=1.0.0
                    
Install as a Cake Tool

Anarchy.Toolkit.Runtime.Web.Swagger

Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Runtime · Package catalog

Swagger/OpenAPI for toolkit REST APIs: the OpenAPI document and the themed Swagger UI.

dotnet add package Anarchy.Toolkit.Runtime.Web.Swagger
  • AddToolkitSwagger(apiName, appSettings, environment, ...) registers the OpenAPI 3.2 document at swagger/spec/swagger.json and serves Swagger UI at /swagger, with GET / redirecting to it.
  • The document declares an oauth2 client-credentials scheme when the settings implement IAuthServiceAppSettings, documents [Authorize] policies (AuthorizeCheckOperationFilter) and the Accept-Encoding header (AcceptEncodingHeaderOperationFilter), describes the runtime (SwaggerDescriptionBuilder, SwaggerDescriptionOptions) and adds a server from BASE_PATH.
  • Hosts composing their own pipeline call AddToolkitSwaggerGen(...) and app.UseToolkitSwagger(...) instead.

When to use it

Use it for REST APIs that publish an OpenAPI document or a Swagger UI. APIs without them only need Anarchy.Toolkit.Runtime.Web, which references neither Swashbuckle nor Microsoft.OpenApi. anarchy-toolkit scaffold api adds it unless --no-swagger is given.

How to use it

public sealed class Startup(IWebHostEnvironment environment, IConfiguration configuration)
    : RestApiWebAppStartupBase<ModuleAppSettings, AppSettings>(environment, configuration)
{
    protected override string ApiName => "Orders API";

    protected override IServiceCollection ConfigureWebCustomServices(IServiceCollection services) =>
        base.ConfigureWebCustomServices(services)
            .AddToolkitSwagger(ApiName, AppSettings, Environment, titlePrefix: "[Orders]");
}

oauthScopes lists the scopes offered by the Swagger UI client-credentials flow, titlePrefix (default [API]) prefixes the document and page titles, and descriptionOptions adds repository, dashboard, documentation and team links to the description.

Swagger UI theme

Swagger UI is themed by default, with the Anarchy palette, header logo (dark text in light mode, white text in dark mode) and favicon, in light and dark mode. Swagger UI starts in dark mode when the system prefers it; the choice made with its header toggle is remembered in the browser. The theme is a mechanism rather than a brand: the stylesheet reads every colour, font and radius from a separate colours stylesheet, so you can rebrand by changing only the colours.

  • Change the colours. Copy wwwroot/css/swagger-colors.css to your API project's wwwroot/css/swagger-colors.css and edit the values. Each colour is a light-dark(<light>, <dark>) pair. The packaged assets follow the usual wwwroot layout (css/swagger-colors.css, css/swagger-theme.css and js/swagger-theme.js in this package; images/logo.png, images/logo-dark.png, and favicon.svg and favicon.png at the root in Anarchy.Toolkit.Runtime.Web), and files in your API project's wwwroot are served first, so a wwwroot/favicon.svg or wwwroot/images/logo.png replaces the packaged one the same way.
  • Point elsewhere. services.Configure<SwaggerThemeOptions>(...) sets ColorsStylesheet, Stylesheet, Script, Logo, DarkLogo, Favicon and FallbackFavicon (relative to the application base path, or absolute). Set Stylesheet to your own file to replace the theme entirely.
  • Turn it off. services.Configure<SwaggerThemeOptions>(theme => theme.Enabled = false) keeps Swagger UI's own look and favicon.

The theme uses system fonts only and changes colours, type and borders, not layouts. Swagger UI's class names are not a stable API, so check the theme after upgrading Swashbuckle.

The OpenAPI document is served as OpenAPI 3.2 by default; set SwaggerOptions.OpenApiVersion with services.Configure<SwaggerOptions>(...) to serve another version.

See the package catalog and toolkit overview.

Third-party dependencies

This package brings these libraries, which its name does not announce:

Library Why In the public API?
Swashbuckle.AspNetCore Generates the OpenAPI document and serves Swagger UI Yes: the operation filters implement its IOperationFilter; SwaggerOptions sets the OpenAPI version
Microsoft.OpenApi The OpenAPI document model Yes: the filters take OpenApiOperation

Releases

See the release notes for the complete release history.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 48 11/27/2026

## Releases

### 1.0.0

- Introduced the package with the Swagger/OpenAPI generation, Swagger UI and theme extracted from `Anarchy.Toolkit.Runtime.Web`.