Purview.Results.ZodSharp.AspNetCore 1.0.0-prerelease.2

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

Purview.Results.ZodSharp.AspNetCore

NuGet version Release

Renders a result failure that carries ZodSharp validation errors as an ASP.NET Core HttpValidationProblemDetails response, produced by the same mapper the ZodSharp exception handler uses — so a validation failure carried by a result and the same failure thrown as a ZodException produce identical responses.

Installation

dotnet add package Purview.Results.ZodSharp.AspNetCore

Quick start

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddZodSharpProblemDetails();
builder.Services.AddResultsHttp();

// Every validation-carrying failure becomes one validation problem, except the codes and categories that a
// rule answers with something else.
builder.Services.AddResultsZodSharpHttp(options => options
    .MapCode("tenant_not_found", StatusCodes.Status404NotFound)
    .MapCategory("invalid_value", StatusCodes.Status422UnprocessableEntity)
);

var app = builder.Build();

app.MapPost("/reconcile", (ReconciliationRequest request) => Reconcile(request)).WithResultsHttp();

AddResultsZodSharpHttp registers the mapping as a failure mapper, so a mapping the host registered for a specific error case always wins, a mapping registered for the error type wins, and a host failure mapper registered before it wins too.

Answering by validation error code or category

Member Purpose
MapCode(string code, int statusCode) Renders the validation problem with a different default status
MapCode(string code, Func<ImmutableArray<ValidationError>, HttpContext, IResult?>) Renders a response of your own
MapCategory(string category, int statusCode) The same, for a category that spans many codes
MapCategory(string category, Func<ImmutableArray<ValidationError>, HttpContext, IResult?>) Renders a response of your own

A rule applies when any of the failure's errors carries its code or category, so a registered code rule is always reachable whatever else the schema reported. Matching walks the code rules first, then the category rules, each in registration order, and finally the default validation problem — a code is narrower than a category, so it wins however the two were registered. A factory that wants stricter semantics returns null to decline the failure, and matching continues:

options
    // A code rule that only answers a failure whose every error is that code.
    .MapCode("tenant_not_found", (errors, context) =>
        errors.All(error => error.Code == "tenant_not_found")
            ? TypedResults.NotFound()
            : null)
    // A category rule that answers the failures the code rule declined.
    .MapCategory("invalid_value", StatusCodes.Status422UnprocessableEntity);

A factory receives the failure's full error set, so a rule never hides the other problems the caller has to fix, and the int statusCode overloads still render every error as an HttpValidationProblemDetails. A code or category registered twice with different behaviour is rejected at configuration time.

API

Member Purpose
AddResultsZodSharpHttp(Action<ZodResultsHttpOptions>? configure = null) Registers the ZodSharp options and adds the validation failure mapper to ResultsHttpOptions
ZodResultsHttpOptions.MapCode / .MapCategory The per-code and per-category rules described above
ZodResultsFailureMapper The mapper itself, for a host that wants to register or compose it by hand
IValidationErrorCarrier.ToValidationProblem(HttpContext, int statusCode = 400) Creates the validation problem for the errors the error value carries
ImmutableArray<ValidationError>.ToValidationProblem(HttpContext, int statusCode = 400) Creates the validation problem for a set of errors
ZodValidationProblems.ToProblem(errors, options, defaultStatusCode = 400, traceId = null) The underlying mapper, for hosts that resolve the options themselves

The status code resolved by ZodProblemDetailsOptions.StatusCodeSelector wins; statusCode (or defaultStatusCode, or a rule's statusCode) is only used when the resolved error type does not define one. The trace identifier is included when ResultsHttpOptions.IncludeTraceId is true (the default).

Examples

src/examples/Examples.AspNetCore.Zod is a runnable minimal-API example where a TenantInputInvalid failure carrying ZodSharp errors becomes a 400 validation problem, while the host's own TenantAlreadyExists mapping still returns 409.

dotnet run --project src/examples/Examples.AspNetCore.Zod --urls http://localhost:5216

The repository README lists the Basic, ZodSharp and ASP.NET Core examples too.

Package Purpose
Purview.Results.ZodSharp Produces the results that carry validation errors
Purview.Results.AspNetCore The result-to-response mapping this package extends

Agent skills

This package ships the purview-results-zodsharp-problems agent skill under .agents/. Repositories that import Purview.BuildSdk get it mirrored into their own .agents/ folder on the next restore or build, so AI agents working there receive the guidance automatically.

License

MIT — see LICENSE.md.

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
1.0.0-prerelease.2 37 9/30/2026
1.0.0-prerelease.1 40 9/30/2026