Toggly.FeatureManagement.NSwag
2.12.2
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
<PackageReference Include="Toggly.FeatureManagement.NSwag" Version="2.12.2" />
<PackageVersion Include="Toggly.FeatureManagement.NSwag" Version="2.12.2" />
<PackageReference Include="Toggly.FeatureManagement.NSwag" />
paket add Toggly.FeatureManagement.NSwag --version 2.12.2
#r "nuget: Toggly.FeatureManagement.NSwag, 2.12.2"
#:package Toggly.FeatureManagement.NSwag@2.12.2
#addin nuget:?package=Toggly.FeatureManagement.NSwag&version=2.12.2
#tool nuget:?package=Toggly.FeatureManagement.NSwag&version=2.12.2
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.AllandRequirementType.Anyfrom 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
- The
FeatureGateOperationProcessorexamines each API endpoint during Swagger document generation - It checks for
[FeatureGate]attributes on both the controller class and action methods - If a
[FeatureGate]attribute is found, it evaluates the associated feature flags usingIFeatureManager - If the feature flags are disabled (based on
RequirementType), the endpoint is excluded from the Swagger document - 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
IFeatureManageris not available in the service provider, endpoints are included by default - The processor supports both
RequirementType.All(all features must be enabled) andRequirementType.Any(at least one feature must be enabled)
| Product | Versions 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. |
-
.NETCoreApp 3.1
- Microsoft.FeatureManagement.AspNetCore (>= 2.6.1)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
.NETStandard 2.1
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.FeatureManagement.AspNetCore (>= 2.6.1)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
net5.0
- Microsoft.FeatureManagement.AspNetCore (>= 2.6.1)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
net6.0
- Microsoft.FeatureManagement.AspNetCore (>= 3.0.0)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
net7.0
- Microsoft.FeatureManagement.AspNetCore (>= 3.0.0)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
net8.0
- Microsoft.FeatureManagement.AspNetCore (>= 4.3.0)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
-
net9.0
- Microsoft.FeatureManagement.AspNetCore (>= 4.3.0)
- NSwag.AspNetCore (>= 14.6.3)
- NSwag.Core (>= 14.6.3)
- NSwag.Core.Yaml (>= 14.6.3)
- NSwag.Generation.AspNetCore (>= 14.6.3)
- Toggly.FeatureManagement (>= 2.12.2)
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 |