v2 - Features / Refactor - #7
Open
kieronlanning wants to merge 42 commits into
Open
Conversation
Its using the .NET 11 (preview) SDK but still targeting .NET Standard 2.1 and .NET 10
Kieron/composition
Kieron/composition
Kieron/adding validators
* 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>
Author
|
@guinhx if you can delete and re-create Everything else is taken care of based on your previous comments... hope that's ok! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
.config/dotnet-tools.jsonto manage .NET tools, includingcsharpierfor code formatting..config/lefthook.ymlto automate commit message linting and code formatting checks via pre-commit and commit-msg hooks.Justfilewith common build, test, lint, and packaging commands to standardize local development workflows.Continuous Integration and Publishing:
.github/workflows/ci.ymlfor automated build and test on push and pull request tomainanddevelopbranches..github/workflows/publish.ymlto 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:
Directory.Packages.propsfor centralized NuGet package version management, including Roslyn, TUnit, and other dependencies, with support for transitive pinning and source generator compatibility..gitattributesto enforce consistent line endings and encoding for various file types, improving cross-platform development..gitignorefiles to.agents/skills/*directories to ignore all files except subdirectories and the.gitignoreitself, keeping the repo clean.Documentation and Examples:
README.mdto 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.