Toggly.FeatureManagement.NSwag
3.14.2
Prefix Reserved
See the version list below for details.
dotnet add package Toggly.FeatureManagement.NSwag --version 3.14.2
NuGet\Install-Package Toggly.FeatureManagement.NSwag -Version 3.14.2
<PackageReference Include="Toggly.FeatureManagement.NSwag" Version="3.14.2" />
<PackageVersion Include="Toggly.FeatureManagement.NSwag" Version="3.14.2" />
<PackageReference Include="Toggly.FeatureManagement.NSwag" />
paket add Toggly.FeatureManagement.NSwag --version 3.14.2
#r "nuget: Toggly.FeatureManagement.NSwag, 3.14.2"
#:package Toggly.FeatureManagement.NSwag@3.14.2
#addin nuget:?package=Toggly.FeatureManagement.NSwag&version=3.14.2
#tool nuget:?package=Toggly.FeatureManagement.NSwag&version=3.14.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: 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.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 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
- 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 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. |
-
.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 (>= 3.14.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 (>= 3.14.2)
-
net10.0
- Microsoft.FeatureManagement.AspNetCore (>= 4.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 (>= 3.14.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 (>= 3.14.2)
-
net6.0
- Microsoft.FeatureManagement.AspNetCore (>= 3.5.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 (>= 3.14.2)
-
net7.0
- Microsoft.FeatureManagement.AspNetCore (>= 3.5.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 (>= 3.14.2)
-
net8.0
- Microsoft.FeatureManagement.AspNetCore (>= 4.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 (>= 3.14.2)
-
net9.0
- Microsoft.FeatureManagement.AspNetCore (>= 4.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 (>= 3.14.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.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 |