[TypeGen]: support external Zod schema overrides - #21
Conversation
MistyKuu
left a comment
There was a problem hiding this comment.
Hey, thanks for this! Splitting TsType (static) and ZodSchema (runtime) makes sense, and the tests pass locally. I left a few inline notes. The import extraction one is the main blocker.
Heads up: ci.yml doesn't run ZibStack.NET.TypeGen.Tests at all, so the green check here doesn't cover your tests. Mind adding a step for it while you're at it?
|
Addressed all six inline review comments in 38d1cd5, including explicit compound-expression imports, local schema references and cycles, collision aliases, parenthesized modifiers, documentation, and compilation tests. CI now runs the TypeGen suite with its Node/Python prerequisites. The first Linux run exposed a pre-existing case-sensitive filename assumption in SampleApiBuildTests; corrected in cfc5ea3. The latest build-and-test check is green (all steps, including TypeGen). |
Summary
Adds a Zod-specific property override for C# types whose runtime validator is supplied by a frontend package or shared schema module.
[TsType]remains responsible for static TypeScript typing. The new[ZodSchema]attribute supplies the runtime Zod expression and optional named import:The same configuration is available fluently for referenced models:
Generated output:
Behavior
z.unknown()fallback.[ZodSchema("expression", ImportFrom = "module")]and both fluent overloads.z.string().startsWith('ord_').PatchField<T>modifiers after the override.z.compile(...), inferred types, generated guards, and TanStack payload validation.The documentation also explains that
z.toZod<T>()requires exact type equality. A schema merely assignable to a[TsType]type may not satisfy conformance. Forzod-geojson, its ownGeoJSONPointandGeoJSONFeatureinferred aliases support exact conformance.Closes #20.
Affected package(s)
Type of change
Examples and documentation
zod-geojson.[TsType]overrides from runtime[ZodSchema]validation.How was this verified?
dotnet test ... --filter "FullyQualifiedName!~CompilationTests"— 262 passed.zod@4.6.1,zod-geojson@1.7.1,@types/geojson, andtsccompilation.GeoJSONPointSchema/GeoJSONFeatureSchemaimports and usages.dotnet build ZibStack.NET.slnx --no-restore— succeeded with 0 errors and no new warnings.The Astro documentation build was attempted, but the existing local
docs/node_modulescontains files that Windows reports as access denied. No documentation-source error was reported before that environment failure.Checklist
master, focused on a single changedocs/src/content/docs/and the package README[Package]: …prefix