Skip to content

v2 - Features / Refactor - #7

Open
kieronlanning wants to merge 42 commits into
guinhx:mainfrom
kieronlanning:main
Open

v2 - Features / Refactor#7
kieronlanning wants to merge 42 commits into
guinhx:mainfrom
kieronlanning:main

Conversation

@kieronlanning

Copy link
Copy Markdown

This pull request introduces foundational configuration and automation for the project, focusing on development tooling, CI/CD, and cross-platform compatibility. It adds essential configuration files for formatting, package management, and automated workflows, and updates documentation to reflect the new structure and supported frameworks.

Key changes:

Tooling and Automation Setup:

  • Added .config/dotnet-tools.json to manage .NET tools, including csharpier for code formatting.
  • Introduced .config/lefthook.yml to automate commit message linting and code formatting checks via pre-commit and commit-msg hooks.
  • Added a Justfile with common build, test, lint, and packaging commands to standardize local development workflows.

Continuous Integration and Publishing:

  • Added .github/workflows/ci.yml for automated build and test on push and pull request to main and develop branches.
  • Updated .github/workflows/publish.yml to use the solution file (ZodSharp.slnx), support multiple .NET versions (8.0, 9.0, 10.0), and the latest actions for checkout and setup-dotnet. [1] [2] [3]

Project and Package Management:

  • Added Directory.Packages.props for centralized NuGet package version management, including Roslyn, TUnit, and other dependencies, with support for transitive pinning and source generator compatibility.
  • Added .gitattributes to enforce consistent line endings and encoding for various file types, improving cross-platform development.
  • Added .gitignore files to .agents/skills/* directories to ignore all files except subdirectories and the .gitignore itself, keeping the repo clean.

Documentation and Examples:

  • Updated README.md to reflect support for .NET 8.0, 9.0, and 10.0, expanded DataAnnotations support, clarified package structure, and provided detailed examples for JSON integration and schema import/export. [1] [2] [3] [4] [5] [6]

These changes lay the groundwork for a modern, maintainable, and cross-platform .NET library with robust developer experience and automation.

Its using the .NET 11 (preview) SDK but still targeting .NET Standard 2.1 and .NET 10
kieronlanning and others added 9 commits July 14, 2026 13:24
* feat: zod json schema support; fixes some errors that seen at example project

* feat(composition): add Zod-style schema-to-value composition (Phase 0)

Add the foundation layer for Zod-style composition with new instance
methods on ZodType that return new composable schemas:

- SuperRefine: context-aware refinement that can emit multiple,
  path-located issues (Zod superRefine)
- Pipe: schema-to-schema chaining, generalizing Transform from
  Func-based to schema-based (Zod pipe)
- Catch: fallback value on validation failure (Zod catch)
- Prefault: substitute and validate when input is default (Zod prefault)

New types: RefineCtx, ZodSuperRefinement, ZodPipe, ZodCatch, ZodPrefault.

Reconcile the generated static composition API: rename And/Or/Refine to
ApplyAnd/ApplyOr/ApplyRefine (value-first helpers) and wire
GenerateCompositionMethods into GenerateSchemaClass (was defined but
never called). Fix two latent generator bugs: stray dollar sign in Or
signature emission and missing double-colon in Refine global::System.Func.

All new code compiles on netstandard2.1 and net10.0. 17 new TUnit tests
added, all passing. Pre-existing generator test failures unrelated.

* feat(composition): add schema-to-schema composition and typed unions (Phase 1)

Add boolean schema composition and typed discriminated unions that work
on .NET 10 and netstandard2.1, forward-compatible with the .NET 11 union
keyword.

New schema-to-schema composition:
- ZodIntersection<T>: validates against both schemas, merges errors
- Instance .And(IZodSchema<T>): returns a new ZodIntersection schema
- Z.Intersection(left, right): factory for intersection
- Instance .Or<TOther>(IZodSchema<TOther>): returns a ZodTypedUnion
- ZodTypedUnion<T1,T2>: tries each option, yields a typed Union<T1,T2>
- Z.Union<T1,T2>(option1, option2): typed union factory

New typed union value types (Unions/):
- IUnion marker interface (forward-compatible with .NET 11 IUnion)
- Union<T1,T2> and Union<T1,T2,T3>: non-boxing readonly structs with
  implicit conversions, TryGetValue (non-boxing), Match, Switch, and
  equality — mirroring the C# 15 union keyword surface

All new code compiles on netstandard2.1 and net10.0. 24 new TUnit tests
added, all passing. Lint clean. Pre-existing generator test failures
unrelated.

* feat(composition): add object-shape composition (Phase 2)

Add Zod-style object-shape manipulation on the dictionary-backed ZodObject:

- Extend(key, schema) / Extend(ZodObject): add or replace fields
- Merge(ZodObject): combine two object shapes
- Pick(keys) / Omit(keys): select or exclude fields
- Partial() / Required(): make all fields optional or required
- Passthrough() / Strict() / Strip(): unknown-key policies (keep, reject, drop)
- Catchall(schema): validate and include unknown keys

New types:
- UnknownKeyPolicy enum (Strip, Passthrough, Strict)
- FieldSchemaWrapper<T>: shared public wrapper from typed schema to
  untyped IZodSchema<object, object>, used by Extend and Catchall

ZodObject now accepts optional constructor parameters for the policy,
optional keys, and catchall schema (backwards compatible). ParseInternal
updated to skip missing optional fields and handle unknown keys per the
configured policy.

All new code compiles on netstandard2.1 and net10.0. 12 new TUnit tests
added, all passing. Lint clean. Pre-existing generator test failures
unrelated.

* feat(composition): add enum, record, and tuple schema types (Phase 3)

Add more Zod-equivalent schema types:

- ZodEnum: string-based enum validation against allowed values
  (Z.Enum("a", "b", "c"))
- ZodNativeEnum<TEnum>: C# enum validation against defined members
  (Z.Enum<Color>()), uses generic Enum.IsDefined on NET5+ and
  non-generic on netstandard2.1
- ZodRecord<TValue>: dictionary validation where all values match a
  schema (Z.Record(Z.Number()))
- ZodTuple<T1,T2> / ZodTuple<T1,T2,T3>: typed tuple validation from
  object arrays, returning ValueTuples (Z.Tuple(Z.String(), Z.Number()))

All new code compiles on netstandard2.1 and net10.0. 19 new TUnit tests
added, all passing. Lint clean. Pre-existing generator test failures
unrelated.

* chore: remove stray COMMIT_MSG.txt from Phase 3 commit

* feat(composition): enable generated schemas to participate in composition (Phase 4)

Make IZodSchemaValidator<T> extend IZodSchema<T> so that generated
*SchemaValidator adapters can be passed as arguments to the full
schema composition API (.And(), .Or(), .Pipe(), Z.Intersection, etc.).

This is a binary-compatible interface addition: existing code using
IZodSchemaValidator<T> only for DI resolution continues to work, while
generated schemas now compose seamlessly with runtime schemas.

New tests:
- SchemaValidatorCompositionTests: 4 runtime tests verifying validators
  can be cast to IZodSchema<T> and passed to And/Intersection/Or
- GeneratedValidator_ImplementsIZodSchema_CanParticipateInComposition:
  source-generator integration test compiling a [ZodSchema] model and
  verifying the generated validator implements IZodSchema<T>

All new code compiles on netstandard2.1 and net10.0. 5 new tests, all
passing. Lint clean. Pre-existing generator test failures unrelated.

* chore: remove stray COMMIT_MSG.txt

* chore: renamed reserved keyword in test

* refactor: mass update to account for source gen framework

* refactor: mass update to account for source gen framework

* refactor: mass update to account for source gen framework

* feat: added Url, Phone, Base64, CreditCard, and Compare rules

* build: updated publish.yaml

* build: multi-target net8.0/net9.0/net10.0, add CI workflow, update README, remove fork tooling

* build: remove netstandard2.1 from library targets, keep source generator on netstandard2.0

* feat(SystemTextJson): add JSON Schema from-json parsing using System.Text.Json

* docs: update README for multi-package layout, multi-targeting, and JSON Schema import

* chore: updated build and warnings

* test: github actions can be slow

---------

Co-authored-by: guinhx <diegosantosaraujo@outlook.com>
@kieronlanning

Copy link
Copy Markdown
Author

@guinhx if you can delete and re-create develop based on main this will be an easy merge.

Everything else is taken care of based on your previous comments... hope that's ok!

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