feat(zod): add Zod v4 schema serializer#82
Conversation
Walks the same intermediate AST that the TypeScript serializer uses. All type mappings, mutations, and overrides applied via the guts pipeline are reflected in the Zod output. Handles interfaces as z.object(), string-literal unions as z.enum(), pointers as .nullable(), omitempty as .optional(), arrays, records, references between schemas, inline object literals, intersections, and operator types (readonly).
|
@Emyrk my agent did this unprompted. Not sure about adding it to guts but it could potentially be an example? Feel free to close or ask for follow-up. 👍🏻 |
|
@mafredri can I speak to your agent? Lol I would like it to add a test so I can see the output |
|
Hey! The agent is at https://dev.coder.com/agents/58b033ba-54bb-4f98-84a4-8264b7f02dd9 if you want to chat with it directly. Added an end-to-end test that runs real Go structs through the full pipeline. Check Run it with Also added heritage support ( |
Adds a testdata/zod package with realistic types (enums, embedded structs, nullable pointers, arrays, maps, self- referencing children) and a golden-file test that runs the full guts pipeline through the Zod serializer. Heritage clauses now emit .extend() for struct embedding. Self-referential types emit z.lazy() to avoid reference- before-declaration errors. The selfName parameter is threaded through exprToZod to detect self-references without global mutable state.
Adds a testdata/zod package with realistic types (enums, embedded structs, nullable pointers, arrays, maps, self- referencing children) and a golden-file test that runs the full guts pipeline through the Zod serializer. Heritage clauses now emit .extend() for struct embedding. Self-referential types emit z.lazy() to avoid reference- before-declaration errors. The selfName parameter is threaded through exprToZod to detect self-references without global mutable state.
New
zodpackage that serializes the guts intermediate AST into Zod v4 schema declarations. Walks the same AST that the TypeScript serializer uses, so all type mappings, mutations, and overrides are reflected.Handles:
z.object(),z.enum(),.nullable(),.optional(),z.array(),z.record(), schema references, inline objects, intersections, operator types.Use case:
coder/agents-chat-actionmaintains hand-written Zod schemas that mirrorcodersdkGo types. These drift when the Go types change (CODAGT-507). This serializer enables codegen from the same source of truth.