Toggly.FeatureManagement.NSwag 2.12.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Toggly.FeatureManagement.NSwag --version 2.12.2
                    
NuGet\Install-Package Toggly.FeatureManagement.NSwag -Version 2.12.2
                    
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="2.12.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toggly.FeatureManagement.NSwag" Version="2.12.2" />
                    
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 2.12.2
                    
#r "nuget: Toggly.FeatureManagement.NSwag, 2.12.2"
                    
#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@2.12.2
                    
#: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=2.12.2
                    
Install as a Cake Addin
#tool nuget:?package=Toggly.FeatureManagement.NSwag&version=2.12.2
                    
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: The Swagger document is generated on-demand, so it always reflects the current state of your feature flags
  • 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 (bypasses NSwag internal cache)
// 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. The documentation always reflects the current state of your feature flags.

Dynamic Updates: The Swagger document is generated on-demand when requested (e.g., when accessing /swagger/v1/swagger.json), so you can turn features on/off dynamically without restarting the application, and the Swagger documentation will update accordingly.

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 was computed.  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.2.4 146 4/8/2026
3.2.3 103 3/24/2026
3.2.2 110 3/2/2026
3.2.1 105 3/1/2026
3.2.0 104 3/1/2026
3.1.1 100 3/1/2026
3.0.4 115 1/27/2026
3.0.3 288 1/19/2026
3.0.2 112 1/18/2026
3.0.1 114 1/18/2026
3.0.0 121 1/17/2026
2.12.3 151 1/7/2026
2.12.2 137 1/3/2026
2.12.1 120 1/2/2026
2.12.0 553 12/10/2025
2.11.0 472 12/9/2025