OrionGuard.Swagger
7.0.0
dotnet add package OrionGuard.Swagger --version 7.0.0
NuGet\Install-Package OrionGuard.Swagger -Version 7.0.0
<PackageReference Include="OrionGuard.Swagger" Version="7.0.0" />
<PackageVersion Include="OrionGuard.Swagger" Version="7.0.0" />
<PackageReference Include="OrionGuard.Swagger" />
paket add OrionGuard.Swagger --version 7.0.0
#r "nuget: OrionGuard.Swagger, 7.0.0"
#:package OrionGuard.Swagger@7.0.0
#addin nuget:?package=OrionGuard.Swagger&version=7.0.0
#tool nuget:?package=OrionGuard.Swagger&version=7.0.0
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.DataAnnotationsattributes are not looked at, and neither is aValidationAttributeof your own that is not one of the seven above — it is skipped in silence. If a file imports both namespaces,RangeandLengthare ambiguous; qualify them or add ausingalias. - It documents attributes, not validators. Rules written in an
AbstractValidator<T>, inValidate.For(...), or asRuleForAsyncnever reach the schema. Only what is on the model does. - A
$refproperty getsrequiredand 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 writesminLength, including on a collection property. It never writesminItems.- It only touches model schemas. No response schemas, no
ProblemDetailsschema; 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 | Versions 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. |
-
net10.0
- OrionGuard (>= 7.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.3)
-
net8.0
- OrionGuard (>= 7.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.3)
-
net9.0
- OrionGuard (>= 7.0.0)
- Swashbuckle.AspNetCore.SwaggerGen (>= 10.2.3)
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 |