Skip to content

feat: add auto-generated Zod schemas via Hey API plugin#70

Merged
MathurAditya724 merged 1 commit intomainfrom
add-zod-plugin
May 6, 2026
Merged

feat: add auto-generated Zod schemas via Hey API plugin#70
MathurAditya724 merged 1 commit intomainfrom
add-zod-plugin

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Add auto-generated Zod v3 schemas from the OpenAPI spec using Hey API's built-in Zod plugin. The schemas are exported from a separate @sentry/api/zod subpath entry point so existing consumers are completely unaffected — only those who opt in by importing from @sentry/api/zod will pull in the zod dependency.

Both the CLI (getsentry/cli) and MCP server (getsentry/sentry-mcp) currently maintain hand-written Zod schemas for Sentry API responses. This change enables them to migrate to auto-generated schemas that stay in sync with the OpenAPI spec automatically.

Usage

import { zAlertRule, zOrganization } from "@sentry/api/zod";

const parsed = zOrganization.parse(rawData);

What changed

  • build.mjs: Enable the zod plugin with compatibilityVersion: 3 (Zod v3 syntax, matching both consumer repos). Default plugins (@hey-api/typescript, @hey-api/sdk) are listed explicitly since adding plugins overrides defaults.
  • build.mjs: Create src/zod.ts entry point and bundle it to dist/zod.js with zod externalized (not bundled — consumers provide their own zod).
  • package.json: Add ./zod subpath export, zod as optional peer dependency, and zod as dev dependency for build-time resolution.

Testing

bun run build && bun run typecheck && bun test — all 28 tests pass, typecheck clean, npm pack produces valid package.

Enable the Hey API Zod plugin to auto-generate Zod v3 schemas from the
OpenAPI spec. The schemas are exported from a separate '@sentry/api/zod'
entry point so existing consumers are unaffected.

- Add 'zod' plugin with compatibilityVersion: 3 to createClient config
- Build a separate dist/zod.js bundle with zod externalized
- Add zod as an optional peer dependency
- Add './zod' subpath export to package.json
@MathurAditya724 MathurAditya724 marked this pull request as ready for review May 6, 2026 00:13
@MathurAditya724
Copy link
Copy Markdown
Member Author

All 5 CI checks passed (Build, Secret Scan, dependency-review, semgrep, warden). Self-review found no issues — the diff is minimal (3 files, 52 insertions), output verified to use correct Zod v3 syntax with zod externalized from the bundle. Marked ready for review.

@MathurAditya724 MathurAditya724 merged commit f90610a into main May 6, 2026
6 checks passed
@MathurAditya724 MathurAditya724 deleted the add-zod-plugin branch May 6, 2026 00:17
MathurAditya724 added a commit to getsentry/sentry-mcp that referenced this pull request May 6, 2026
Picks up v0.141.0 which adds auto-generated Zod schemas via a new
'@sentry/api/zod' subpath export (getsentry/sentry-api-schema#70).
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.

1 participant