Skip to content

feat: add Zod schema registration to OutputConfig for typed JSON output #566

@BYK

Description

@BYK

Summary

Add an optional schema field to OutputConfig<T> so commands can register the Zod schema for their JSON output type. This enables:

  1. Typed SDK generation — Build-time codegen can read schemas from the command tree and generate TypeScript return types automatically, eliminating the need for a manual type map.

  2. JSON output documentation — The --json mode can be documented with exact field-level schemas, including which fields are optional, enum values, nested structures, etc.

  3. Runtime validation — Optionally validate command output against the schema in dev/test modes to catch type drift.

  4. JSON Schema generation — Export schemas as JSON Schema for consumers who want to validate output in other languages.

Proposed API

// In buildCommand:
output: {
  human: formatIssueList,
  schema: IssueListOutputSchema, // NEW — Zod schema for the JSON output
  jsonExclude: ["humanOnlyField"],
}

The schema describes the shape of the data AFTER jsonTransform and jsonExclude are applied — i.e., what the consumer actually receives.

Where schemas already exist

Most API response types in src/types/sentry.ts already have Zod schemas (e.g., SentryUserSchema, SentryTeamSchema, SpanListItemSchema). For list commands, the envelope { data: T[], hasMore: boolean, nextCursor?: string } would need a generic wrapper.

Integration points

  • src/lib/formatters/output.tsOutputConfig<T> type gains optional schema field
  • src/lib/introspect.ts — Expose schema from command metadata for codegen
  • script/generate-sdk.ts — Read schemas to auto-generate typed return types
  • script/generate-skill.ts — Could emit JSON Schema in SKILL.md for agent consumption

Context

This was identified during the library export work (#565) as the principled solution for typed SDK return values. Currently, a manual type map bridges the gap, but schema registration would make it automatic and self-documenting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions