Purview.ZodSharp.AspNetCore.OpenApi 3.0.0-prerelease.2

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

Purview.ZodSharp.AspNetCore.OpenApi

NuGet version Release

OpenAPI integration for Purview.ZodSharp: ASP.NET Core 11 OpenAPI transformers that make the document describe exactly what ZodSharp enforces — constraints, formats, unions, maps and the validation error contract — with one line of setup.

net11.0 only: ASP.NET Core 11 builds documents on the Microsoft.OpenApi 3.x object model.

Installation

dotnet add package Purview.ZodSharp.AspNetCore.OpenApi

Usage

using Microsoft.AspNetCore.OpenApi; // AddZodSharp(this OpenApiOptions) lives here; it is not an implicit using

builder.Services.AddZodSharp(options => options.ScanAssemblies.Add(typeof(Program).Assembly));
builder.Services.AddOpenApi(options => options.AddZodSharp());

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

Options:

builder.Services.AddOpenApi(options => options.AddZodSharp(zod =>
{
    zod.EmitVendorExtensions = true;       // x-zod-* for rules without a JSON Schema keyword
    zod.DiscriminatedUnionsAsOneOf = true; // oneOf + discriminator for polymorphic types
    zod.DescribeValidationProblems = true; // 400 ZodValidationProblemDetails on validated endpoints
}));

All three default to true (ZodOpenApiOptions). Trimmed and Native AOT apps can register their validators with the generated AddZodSharp{Assembly}Schemas() instead of assembly scanning.

What it describes

The source of truth is ZodSharp's own JSON Schema for a type: the generated BuildJsonSchema() of a [ZodSchema] type, or a runtime schema registered in IZodSchemaFactory. A type ZodSharp does not know is left exactly as ASP.NET Core produced it.

ZodSharp OpenAPI keyword
MinLength/MaxLength/Length/StringLength minLength/maxLength (strings), minItems/maxItems (collections), minProperties/maxProperties (maps)
MinValue/MaxValue/GreaterThanOrEqual/LessThanOrEqual minimum/maximum
GreaterThan/LessThan exclusiveMinimum/exclusiveMaximum
MultipleOf multipleOf
Int type: integer
SafeInteger type: integer with ZodSharp's safe range
Regex/RegularExpression pattern (several become allOf)
StartsWith/EndsWith/Includes pattern, plus x-zod-startsWith/x-zod-endsWith/x-zod-includes
Email/EmailAddress format: email
Url format: uri
UUID(version) format: uuid, a version pattern and x-zod-uuidVersion
IPAddress(IPv4/IPv6) format: ipv4/ipv6
Cidr, JWT x-zod-cidr, x-zod-jwt (listed under x-zodsharp-unsupported)
DatetimeString/DateString format: date-time (with the UTC pattern)/format: date
TimeString a local-time pattern and x-zod-format: time
Duration format: duration
Base64String contentEncoding: base64
AllowedValues/enum members enum
DeniedValues not: { enum: [...] }
[Display(Description)] description

Members ZodSharp rejects when absent (non-nullable references, [Required], [RequiredZod]) are listed in required, and nullability uses type: [x, "null"]. When a DataAnnotation the platform mapped disagrees with ZodSharp, ZodSharp's value is written — it is the validator that enforces the request — and in Development the override is logged at Debug.

Polymorphic types ([JsonPolymorphic]) are described with oneOf and the platform's discriminator. A C# union keeps the platform's anyOf; ZodSharp only constrains each case.

Validation problem responses

Every operation that binds a ZodSharp-validated parameter (a body, an [AsParameters] container, or a union of ZodSharp cases) lists 400 — and 422 when an ErrorType registered in the ErrorTypeRegistry uses it — as application/problem+json with the shared ZodValidationProblemDetails and ZodValidationIssue component schemas. A 400 the endpoint already declares with ProducesValidationProblem() is merged into rather than duplicated.

Documentation

License

MIT — see the package metadata in Purview.ZodSharp.AspNetCore.OpenApi on NuGet.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
3.0.0-prerelease.2 55 11/2/2026