Repository navigation
feat!: switch to Zod v4 types - #97
Conversation
- Add `--format zod4` to emit Zod v4-compatible TypeScript type
annotations while keeping `--format zod` for Zod v3 compatibility.
- Zod v3 and Zod v4 have mutually exclusive generic type constraints
for unions, string enums, and non-empty arrays, preventing generated
schemas with explicit type annotations from compiling under Zod v4.
- In `zod4` mode, emit `z.ZodUnion<readonly [...]>`, record-based
`z.ZodEnum<{ [K]: K }>`, and single-parameter `z.ZodArray<T>`.
Fixes #95
OrKoN
left a comment
There was a problem hiding this comment.
-
In
src/engines/zod.rsvisit_identifier, make theurioutput depend on the version: V3 should emitz.ZodString/z.string().url(), and V4 should keepz.ZodURL/z.url(). The README now says--format zodtargets Zod v3, butz.url()andz.ZodURLonly exist in Zod v4, so v3 output breaks for any CDDL that usesuri(seeprelude_text_types). -
In
tests/zod4.rs, don't copy the wholetest!macro and file list fromtests/zod.rs. Instead, add a version argument to one shared macro (or add azod4_variant insidetests/zod.rs). With two copies, it's easy to add a new example to one format and forget the other. -
In
src/main.rs, merge theEngineType::ZodandEngineType::Zod4arms into one: pick theVersionfirst, then callwith_writers_and_versiononce. As written, the preamble/visit/postamble sequence is copied, and the two copies can drift apart. -
Add
Debugto the derives on the new publicpub enum Version, or implementDefaultreturningV3, to match other public types.with_writerscould then callVersion::default()instead of hard-codingV3.
I dropped support of zod v3 completely. PTAL |
--format zod4 for Zod v4 type annotations🤖 I have created a release *beep* *boop* --- ## [0.2.0](cddlconv-v0.1.12...cddlconv-v0.2.0) (2026-09-29) ### ⚠ BREAKING CHANGES * switch to Zod v4 types ([#97](#97)) ### Features * switch to Zod v4 types ([#97](#97)) ([716b788](716b788)), refs [#95](#95) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Alternative to #96
--format zodand document the
--format <type-script|zod>CLI flag inREADME.md.annotations to Zod v3 syntax, breaking compilation against Zod v4
even though
--format zodalready targets Zod v4 (e.g.,z.ZodURL/z.url()).z.ZodUnion<readonly [...]>, record-basedz.ZodEnum<{ [K]: K }>, and single-parameterz.ZodArray<T>.Fixes #95