Kalicz.StrongTypes.OpenApi.Microsoft 1.1.0

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

Kalicz.StrongTypes.OpenApi.Microsoft

NuGet version Downloads License

OpenAPI schema plumbing for Kalicz.StrongTypes.

Out of the box Microsoft.AspNetCore.OpenApi describes the raw CLR shape of strong types — so a NonEmptyString property shows up as a class with a Value field, Positive<int> as a wrapper object, and Maybe<T> as the full union surface. This package registers schema transformers that rewrite those schemas to match the JSON the converters actually emit, so generated clients and API explorers see the real wire format.

If your app uses Swashbuckle (AddSwaggerGen()) instead, install Kalicz.StrongTypes.OpenApi.Swashbuckle — it provides the same schema corrections against Swashbuckle's pipeline.

Install

dotnet add package Kalicz.StrongTypes.OpenApi.Microsoft

Register

builder.Services.AddOpenApi(options => options.AddStrongTypes());

var app = builder.Build();
app.MapOpenApi();

What it does

  • NonEmptyString{ "type": "string", "minLength": 1 }
  • Positive<T> → underlying primitive with exclusiveMinimum: 0
  • NonNegative<T> → underlying primitive with minimum: 0
  • Negative<T> → underlying primitive with exclusiveMaximum: 0
  • NonPositive<T> → underlying primitive with maximum: 0
  • NonEmptyEnumerable<T> and INonEmptyEnumerable<T>{ "type": "array", "minItems": 1, "items": <T schema> }
  • Maybe<T> → object wrapper { "Value": <T schema, nullable> } matching the converter's on-the-wire format.

Data annotations

Both ASP.NET Core OpenAPI pipelines drop every ValidationAttribute on a property whose CLR type carries a custom JsonConverter — which every strong-type wrapper does — collapsing the property to a bare $ref to the wrapper component.

This package re-applies them: every annotation Microsoft.AspNetCore.OpenApi natively supports on a primitive-typed property also works on a wrapper-typed one. Caller bounds compose with the wrapper's floor under tighter-wins rules: the wrapper never relaxes a caller's constraint, and a caller bound that would loosen the wrapper's floor is ignored.

public sealed record CreateUserRequest(
    [StringLength(50, MinimumLength = 3)]
    [RegularExpression("^[a-zA-Z0-9_]+$")]
    NonEmptyString Username,

    [Range(18, 120)]
    Positive<int> Age,

    [MaxLength(10)]
    NonEmptyEnumerable<NonEmptyString> Tags,

    [Url]
    NonEmptyString Website,

    [Description("Short user tagline")]
    NonEmptyString Tagline);

On the wire:

Property Resulting schema
Username { "type": "string", "minLength": 3, "maxLength": 50, "pattern": "^[a-zA-Z0-9_]+$" }
Age { "type": "integer", "format": "int32", "minimum": 18, "maximum": 120 }
Tags { "type": "array", "minItems": 1, "maxItems": 10, "items": { "type": "string", "minLength": 1 } }
Website { "type": "string", "minLength": 1, "format": "uri" }
Tagline { "type": "string", "minLength": 1, "description": "Short user tagline" }

A few attributes are intentionally not propagated because the underlying pipeline doesn't honor them on a primitive-typed property either, and the wrapper-typed surface stays consistent with the primitive-typed surface on each pipeline:

  • [EmailAddress]Microsoft.AspNetCore.OpenApi doesn't write format: "email" for it. The Swashbuckle adapter does propagate it (because Swashbuckle's DataAnnotationsSchemaFilter does).
  • [DefaultValue] — the framework's own default-value handler crashes when the attribute's underlying value (e.g. string) doesn't match the property's declared wrapper type (e.g. NonEmptyString). Apply [DefaultValue] only to primitive-typed properties.
Product Compatible and additional computed target framework versions.
.NET 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
1.1.0 90 5/5/2026