Skip to content

Zod(POC): Initial jenny for schema generation#1111

Draft
kristinademeshchik wants to merge 5 commits into
mainfrom
KD/zod-poc
Draft

Zod(POC): Initial jenny for schema generation#1111
kristinademeshchik wants to merge 5 commits into
mainfrom
KD/zod-poc

Conversation

@kristinademeshchik
Copy link
Copy Markdown

@kristinademeshchik kristinademeshchik commented May 20, 2026

Adds a Zod jenny that generates Zod v4 schemas from CUE kinds. Output is intended for runtime validation of payloads (e.g. Grafana's dashboard mutation API) and for LLM tool-call schemas via z.toJSONSchema().

Known issues

  • Numeric type fidelity — uint* doesn't add .nonnegative(); bit widths don't add .gte/.lte constraints; z.number() accepts NaN/Infinity. Affects e.g. revision: uint16 in v2beta1.
  • Recursive cycles trip TS strict-mode inference (TS7022/TS7024) on the layout/tab/formatter groups. Suppressed via file-level // @ts-nocheck for now; proper fix is explicit z.ZodType<X> annotations on cycle members via SCC detection.

Generated dashboards zod schemas - grafana/grafana#125222

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Note: the diff show code changes that would be introduced by this PR to the output of the Grafana Foundation SDK codegen pipeline.

See full diff.

🔎 Changes to Grafana Foundation SDK

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an initial “zod” output language to the codegen pipeline, generating Zod v4 schemas from the CUE-derived AST for runtime validation and JSON Schema export.

Changes:

  • Extend pipeline output configuration to support a new zod language (config + wiring).
  • Introduce a Zod jenny that emits schemas.gen.ts files with Zod schemas for AST types.
  • Add Zod-specific output options (layout/filename/defaults/object unknown-key behavior).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
schemas/pipeline.json Adds zod to the pipeline output schema and defines ZodConfig.
internal/jennies/zod/jennies.go Defines Zod language/config and compiler passes used for Zod emission.
internal/jennies/zod/rawtypes.go Implements the core Zod schema emitter (structs/scalars/refs/enums/unions/etc.).
internal/jennies/zod/tools.go Adds helpers for output paths, TS literal formatting, field quoting, and descriptions.
internal/codegen/pipeline.go Wires zod into language selection in the pipeline.
internal/codegen/output.go Adds zod to the YAML output-language struct and parameter interpolation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/jennies/zod/rawtypes.go
Comment thread internal/jennies/zod/rawtypes.go
Comment thread internal/jennies/zod/rawtypes.go
Comment thread internal/jennies/zod/rawtypes.go Outdated
Comment thread internal/jennies/zod/rawtypes.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants