OrionGuard.Swagger 7.0.0

dotnet add package OrionGuard.Swagger --version 7.0.0
                    
NuGet\Install-Package OrionGuard.Swagger -Version 7.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="OrionGuard.Swagger" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OrionGuard.Swagger" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OrionGuard.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 OrionGuard.Swagger --version 7.0.0
                    
#r "nuget: OrionGuard.Swagger, 7.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 OrionGuard.Swagger@7.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=OrionGuard.Swagger&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OrionGuard.Swagger&version=7.0.0
                    
Install as a Cake Tool

OrionGuard.Swagger

Publishes the rules you already enforce: a Swashbuckle schema filter that turns the OrionGuard attributes on your models into OpenAPI constraints, so the documented contract matches the one the server checks.

dotnet add package OrionGuard.Swagger
using Microsoft.Extensions.DependencyInjection;
using Moongazing.OrionGuard.Attributes;
using Moongazing.OrionGuard.Swagger;

public sealed class CreateUserRequest
{
    [NotNull, Email] public string Email { get; set; } = "";
    [Length(8, 100)] public string Password { get; set; } = "";
    [Range(13, 120)] public int Age { get; set; }
    [Regex("^[a-z0-9-]+$")] public string? Slug { get; set; }
    [Positive] public decimal Budget { get; set; }
}

public static class SwaggerSetup
{
    public static void Add(IServiceCollection services)
    {
        services.AddSwaggerGen();
        services.AddOrionGuardSwagger();
    }
}

The generated document now carries required: [email], format: email, minLength/maxLength on password, minimum/maximum on age, pattern on slug and exclusiveMinimum: 0 on budget — so client generators and API explorers show the same limits the request will be held to. The core OrionGuard package comes along as a dependency.

AddOrionGuardSwagger() registers OrionGuardSchemaFilter through services.Configure<SwaggerGenOptions>(...). It does not call AddSwaggerGen(), so your existing Swashbuckle setup stays as it is; options.SchemaFilter<OrionGuardSchemaFilter>() inside AddSwaggerGen does the same job if you prefer to wire it there.

What each attribute writes

Attribute Schema change
[NotNull] Adds the property to the parent schema's required, and removes null from the property's type
[NotEmpty] minLength: 1
[Length(min, max)] minLength, maxLength
[Range(min, max)] minimum, maximum, written with the invariant culture
[Email] format: email
[Regex(pattern)] pattern
[Positive] exclusiveMinimum: 0 — the numeric form OpenAPI 3.1 and JSON Schema 2020-12 use

What this does not do

  • It reads OrionGuard attributes only. System.ComponentModel.DataAnnotations attributes are not looked at, and neither is a ValidationAttribute of your own that is not one of the seven above — it is skipped in silence. If a file imports both namespaces, Range and Length are ambiguous; qualify them or add a using alias.
  • It documents attributes, not validators. Rules written in an AbstractValidator<T>, in Validate.For(...), or as RuleForAsync never reach the schema. Only what is on the model does.
  • A $ref property gets required and nothing else. When a property's schema is a reference to a shared component, the component is left untouched — changing it would affect every other use of that type.
  • Renamed properties are skipped. Matching is on the camelCase form of the CLR property name; a property renamed with [JsonPropertyName], or by a naming policy other than camelCase, is not found and is left unchanged.
  • [NotEmpty] always writes minLength, including on a collection property. It never writes minItems.
  • It only touches model schemas. No response schemas, no ProblemDetails schema; OrionGuard.AspNetCore produces those at runtime, and you document them the usual Swashbuckle way.

Targets

net8.0, net9.0, net10.0; Swashbuckle.AspNetCore.SwaggerGen 10.x, which brings Microsoft.OpenApi 2.x and the OpenAPI 3.1 object model. Swashbuckle 9 and earlier are not compatible — the filter implements the 10.x Apply(IOpenApiSchema, ...) signature.

With the rest of OrionGuard

OrionGuard · OrionGuard.AspNetCore (answers a failed request with ProblemDetails) · OrionGuard.OpenApi — the same idea in reverse, generating a validator from an OpenAPI document

Documentation

License

MIT. See LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
7.0.0 38 9/20/2026
6.7.0 120 7/20/2026
6.6.2 130 6/20/2026
6.6.1 120 6/20/2026
6.6.0 124 6/19/2026
6.5.30 137 6/17/2026
6.5.29 113 6/15/2026
6.5.28 115 6/15/2026
6.5.27 113 6/15/2026
6.5.26 111 6/13/2026
6.5.25 112 6/13/2026
6.5.24 118 6/12/2026
6.5.23 122 6/12/2026
6.5.22 121 6/11/2026
6.5.21 109 6/11/2026
6.5.20 108 6/11/2026
6.5.19 114 6/11/2026
6.5.18 111 6/11/2026
6.5.16 113 6/11/2026
6.5.15 116 6/11/2026
Loading failed