Repository navigation
Conversation
| @@ -0,0 +1,3 @@ | |||
| Choice = text / int | |||
There was a problem hiding this comment.
All tests in tests/typescript.rs and tests/zod.rs use insta::assert_snapshot! against the shared CDDL fixtures in examples/.
Adding a separate examples/zod4_compat.cddl with manual assert!(stdout.contains(...)) checks has two drawbacks:
Choice = text / intonly exercises 1 of the 6z.ZodUnioncode paths (visit_type), leaving the other 5 (visit_array, bounded array occurrences, optionalTypeGroupname, optionalInlineGroup, andvisit_group) untested forzod4.- Every other file in
examples/is snapshot-tested across bothtests/typescript.rsandtests/zod.rs.
Could we instead add tests/zod4.rs (mirroring tests/zod.rs with insta::assert_snapshot! over the existing examples/ fixtures) and drop examples/zod4_compat.cddl?
| write!(self.stdout, "z.ZodEnum<{{"); | ||
| for type2 in t.type_choices.iter().map(|choice| &choice.type1.type2) { | ||
| if let cddl::ast::Type2::TextValue { value, .. } = type2 { | ||
| write!(self.stdout, "\"{}\":\"{}\";", value, value); |
There was a problem hiding this comment.
| write!(self.stdout, "\"{}\":\"{}\";", value, value); | |
| write!(self.stdout, "\"{}\":\"{}\",", value, value); |
Nit: Use , rather than ; to stay consistent with z.ZodObject<{...}> member separators elsewhere in src/engines/zod.rs (and with the original output in #90).
| #[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
| enum Version { | ||
| V3, | ||
| V4, | ||
| } | ||
|
|
There was a problem hiding this comment.
Nit: Rather than keeping enum Version private and adding a dedicated with_writers_zod4 method, consider making pub enum Version { V3, V4 } (line 50) and pub fn with_writers_for_version(stdout: Stdout, stderr: Stderr, version: Version) (line 95) public (with with_writers defaulting to Version::V3). That keeps the Engine API extensible without adding a new constructor per version.
Alternative to #96 - Emit Zod v4-compatible TypeScript type annotations in `--format zod` and document the `--format <type-script|zod>` CLI flag in `README.md`. - Commit 4cc5d36 (#92) switched enum, union, and non-empty array type annotations to Zod v3 syntax, breaking compilation against Zod v4 even though `--format zod` already targets Zod v4 (e.g., `z.ZodURL` / `z.url()`). - Emit `z.ZodUnion<readonly [...]>`, record-based `z.ZodEnum<{ [K]: K }>`, and single-parameter `z.ZodArray<T>`. Fixes #95
|
please note that the original issue is already addressed: #97 |
Fixes #95
Summary
--format zod4mode while keeping--format zodbackward-compatible with Zod v3readonlyunion tuples, enum record types, and single-parameterZodArrayannotationsValidation
cargo testgit diff --checkzod4output type-checks withzod@4+ TypeScriptzodoutput type-checks withzod@3+ TypeScriptcargo run -- --helpexposeszod4as a format option