Skip to content

[TypeGen]: add Zod 4.6 compilation and validation - #19

Open
RejectKid wants to merge 1 commit into
MistyKuu:masterfrom
RejectKid:zod-4-6-support
Open

[TypeGen]: add Zod 4.6 compilation and validation#19
RejectKid wants to merge 1 commit into
MistyKuu:masterfrom
RejectKid:zod-4-6-support

Conversation

@RejectKid

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in support for Zod 4.6's schema compiler and validation API while preserving the current generated output by default.

  • Emits z.compile(...), z.toZod<T>()(...), and generated isX(value) guards when enabled.
  • Emits z.lazy(...) only on cyclic schema edges, including self-referential DTOs.
  • Preserves PatchField<T> omission semantics and keeps nullable schemas aligned with generated TypeScript in conformance mode.
  • Adds source-generated Zod format overrides for email, URL, UUID, ISO date/date-time, hostname, ULID, NanoID (including custom length), Base64, Base64URL, credit cards, and IBANs.
  • Adds source-generated server-side IBAN validation through [ZIban] and .Iban(), and aligns credit-card validation with Zod's 12-19 digit behavior.
  • Lets TanStack Query clients parse requests and/or responses through generated schemas at the network boundary.
  • Updates the Zod test toolchain to 4.6.1.

The new behavior remains opt-in:

b.Zod(z =>
{
    z.Compilation = ZodCompilationMode.Compile;
    z.ConformToTypeScriptTypes = true;
    z.EmitValidationGuards = true;
});

b.TanStackQuery(q =>
    q.PayloadValidation = QueryPayloadValidation.RequestsAndResponses);

b.ForType<Payment>()
    .Property(x => x.PublicToken)
    .ZodNanoId(16);

Examples and documentation

The TypeGen sample now demonstrates compiled/conforming schemas, validation guards, response parsing, credit-card and IBAN formats, ULIDs, hostnames, Base64/Base64URL, custom-length NanoIDs, and recursive models. The Validation sample demonstrates both [ZIban] and fluent .Iban() usage.

The package README and documentation site pages include configuration and generated-code examples. A design note records the Zod 4.6 choices, compatibility behavior, and deferred follow-ups.

Affected package(s)

  • ZibStack.NET.TypeGen
  • ZibStack.NET.TypeGen.Abstractions
  • ZibStack.NET.Validation
  • Samples and docs

Type of change

  • Bug fix
  • New feature
  • Generator / generated-code behavior change
  • Analyzer / diagnostic change
  • Docs only
  • Build / tooling

How was this verified?

  • dotnet build ZibStack.NET.slnx --no-restore — succeeded with 0 errors and no new warnings.
  • Focused TypeGen emitter/configuration/real-TypeScript compilation tests — 69 passed. The compilation tests install Zod 4.6.1 and run tsc against generated schemas and TanStack clients.
  • dotnet test packages/ZibStack.NET.Validation/tests/ZibStack.NET.Validation.Tests/ZibStack.NET.Validation.Tests.csproj --no-restore — 73 passed.
  • Both TypeGen and Validation sample projects build and exercise source generation.

The solution continues to report existing warnings from vulnerable sample dependencies, intentionally unsupported sample DTO types, and the existing DTO sample generator warning.

Checklist

  • Branched from master, focused on a single change
  • Tests added or updated (generator behavior asserted where applicable)
  • Docs updated under docs/src/content/docs/ and the package README
  • Build is clean — no new warnings
  • Commit subjects use the [Package]: … prefix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant