Toggly.FeatureManagement.NSwag 3.13.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Toggly.FeatureManagement.NSwag --version 3.13.0
                    
NuGet\Install-Package Toggly.FeatureManagement.NSwag -Version 3.13.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="Toggly.FeatureManagement.NSwag" Version="3.13.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toggly.FeatureManagement.NSwag" Version="3.13.0" />
                    
Directory.Packages.props
<PackageReference Include="Toggly.FeatureManagement.NSwag" />
                    
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 Toggly.FeatureManagement.NSwag --version 3.13.0
                    
#r "nuget: Toggly.FeatureManagement.NSwag, 3.13.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 Toggly.FeatureManagement.NSwag@3.13.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=Toggly.FeatureManagement.NSwag&version=3.13.0
                    
Install as a Cake Addin
#tool nuget:?package=Toggly.FeatureManagement.NSwag&version=3.13.0
                    
Install as a Cake Tool

ASP.NET Core Feature Flag Extensions for NSwag

Automatically exclude API endpoints from Swagger/OpenAPI documentation when their associated feature flags are disabled. This package integrates Toggly feature flags with NSwag to keep your API documentation in sync with your feature flag state.

Installation

dotnet add package Toggly.FeatureManagement.NSwag

Features

  • Automatic Filtering: Endpoints with [FeatureGate] attributes are automatically excluded from Swagger when their feature flags are disabled
  • Dynamic Updates: By default, the Swagger document is generated for each request, so request-scoped feature gates are evaluated for that request
  • Controller & Action Support: Works with both controller-level and action-level [FeatureGate] attributes
  • Requirement Types: Supports both RequirementType.All and RequirementType.Any from FeatureGateAttribute

Usage

Basic Setup

In your Startup.cs or Program.cs, add the feature gate filtering to your NSwag configuration:

using Toggly.FeatureManagement.NSwag.Configuration;

services.AddOpenApiDocument((config, services) =>
{
    config.Title = "My API";
    config.DocumentName = "v1";
    
    // Add feature gate filtering
    config.AddFeatureGateFiltering(services);
    
    // ... rest of your NSwag configuration
});

// Serve the filtered document with per-request generation by default
// Important: use UseFeatureAwareOpenApi instead of UseOpenApi
app.UseFeatureAwareOpenApi();
app.UseSwaggerUi();

Example Controller

using Microsoft.FeatureManagement.Mvc;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
[FeatureGate(FeatureFlags.ExperimentalFeature)]
public class ExperimentalController : ControllerBase
{
    [HttpGet]
    public IActionResult Get()
    {
        return Ok("This endpoint is only visible in Swagger when ExperimentalFeature is enabled");
    }
}

Before

Without this package, all endpoints appear in Swagger regardless of feature flag state. Users might see endpoints in the documentation that are actually disabled, leading to confusion.

After

With Toggly.FeatureManagement.NSwag, endpoints are automatically excluded from Swagger when their feature flags are disabled. With default settings, the document reflects each request's feature-gate state.

Dynamic Updates: With the default settings, the Swagger document is generated on each request (e.g., when accessing /swagger/v1/swagger.json). Turning a feature on or off changes the next requested document without restarting the application.

Optional document caching

UseFeatureAwareOpenApi generates a fresh document for each request unless you set CreateDocumentCacheKey. This protects request-scoped feature gates from reusing another request's schema. If your application has a small, fixed set of document variants, configure CreateDocumentCacheKey with one key for each complete variant.

The key must distinguish every input that can change the generated document: feature-gate outcomes, request origin, and any request data used by PostProcess. Cache only a bounded set of variants; do not use user IDs or other high-cardinality identities as keys. The middleware retains at most 32 explicit-key documents and evicts older entries when the limit is reached. Reusing a key for different gate states can disclose an endpoint in another request's schema. OpenAPI filtering does not replace endpoint authorization.

How It Works

  1. The FeatureGateOperationProcessor examines each API endpoint during Swagger document generation
  2. It checks for [FeatureGate] attributes on both the controller class and action methods
  3. If a [FeatureGate] attribute is found, it evaluates the associated feature flags using IFeatureManager
  4. If the feature flags are disabled (based on RequirementType), the endpoint is excluded from the Swagger document
  5. The document is generated on-demand, ensuring it always reflects the current feature flag state

Requirements

  • .NET Standard 2.1 or later
  • NSwag.AspNetCore 14.6.3 or compatible
  • Microsoft.FeatureManagement.AspNetCore 4.3.0 or compatible
  • Toggly.FeatureManagement (base package)

Notes

  • Endpoints without [FeatureGate] attributes are always included in Swagger
  • If IFeatureManager is not available in the service provider, endpoints are included by default
  • The processor supports both RequirementType.All (all features must be enabled) and RequirementType.Any (at least one feature must be enabled)
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.15.0 97 11/18/2026
3.14.3 183 10/24/2026
3.14.2 118 10/22/2026
3.14.1 122 10/17/2026
3.13.3 139 10/6/2026
3.13.2 103 10/6/2026
3.13.1 102 10/6/2026
3.13.0 111 10/6/2026
3.12.12 112 10/5/2026
3.12.11 106 10/5/2026
3.12.10 124 10/5/2026
3.12.9 113 10/4/2026
3.12.8 120 10/4/2026
3.12.7 115 10/4/2026
3.12.6 121 10/1/2026
3.12.5 118 9/30/2026
3.12.4 113 9/30/2026
3.12.3 100 9/30/2026
3.12.2 125 9/29/2026
3.12.1 104 9/29/2026
Loading failed