You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: skills/fuz-stack/references/zod-schemas.md
+52-8Lines changed: 52 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,21 +23,24 @@ defaults, metadata, CLI help text, and serialization.
23
23
| Foundation |`@fuzdev/fuz_util/zod.ts`| Schema introspection — extract descriptions, defaults, aliases, types, properties; unwrap wrappers; check optional/nullable/default; format values for display |
24
24
| Cell helpers |`@fuzdev/zzz/zod_helpers.ts`|`Uuid`, `Datetime` branded types and factories; schema unwrapping; field extraction; validation error formatting |
25
25
| CLI |`@fuzdev/fuz_app/cli/args.ts`, `help.ts`| Schema-validated CLI arg parsing; schema-driven help text generation |
26
-
| HTTP |`@fuzdev/fuz_app/http/schema_helpers.ts`|`schema_to_surface()` exports JSON Schema via `z.toJSONSchema()` for snapshot-testable API surfaces |
26
+
| HTTP |`@fuzdev/fuz_app/http/schema_helpers.ts`|`schema_to_surface()` exports JSON Schema via `z.toJSONSchema()` for snapshot-testable API surfaces; `instanceof` checks for schema type detection|
27
27
| Testing |`@fuzdev/fuz_app/testing/schema_generators.ts`| Schema-driven test data generation — valid bodies, adversarial inputs |
28
28
29
29
## Core Conventions
30
30
31
31
1.**`z.strictObject()`** — default for all object schemas, including inside
32
32
`z.discriminatedUnion()` and `z.union()`. Rejects unknown keys.
33
-
**Exception**: external data (`z.looseObject()` or `z.object()` with
34
-
comment explaining why).
33
+
**Exceptions**: external data (`z.looseObject()` or `z.object()` with
34
+
comment explaining why); response/error schemas consumed by clients
35
+
(`z.looseObject()` — allows adding fields without breaking consumers).
35
36
2.**PascalCase naming** — schema and inferred type share the same name.
36
37
3.**`.meta({description: '...'})`** — not `.describe()`. `.meta()` supports
37
38
additional keys (`aliases`, `sensitivity`).
38
39
4.**`safeParse` at boundaries** — graceful errors for external input (HTTP
39
-
requests, API responses). `parse` for internal assertions, config loading,
40
-
CLI args, and factory functions where failure is fatal.
40
+
requests, API responses). `parse` for internal assertions, CLI args, and
41
+
factory functions where failure is fatal. `safeParse` + custom throw when
42
+
you need better error context than `parse` provides (e.g., env loading).
43
+
`safeParse` + return null for optional config files that may be absent.
0 commit comments