Skip to content

feat(zod): support JSON schema registries#1695

Merged
dinwwwh merged 2 commits into
middleapi:mainfrom
dinwwwh:claude/zod-json-schema-registries-3276a9
Jul 20, 2026
Merged

feat(zod): support JSON schema registries#1695
dinwwwh merged 2 commits into
middleapi:mainfrom
dinwwwh:claude/zod-json-schema-registries-3276a9

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Jul 20, 2026

Copy link
Copy Markdown
Member

Brings the v1 JSON_SCHEMA_REGISTRY, JSON_SCHEMA_INPUT_REGISTRY, and JSON_SCHEMA_OUTPUT_REGISTRY to @orpc/zod v2, so users can customize the generated JSON schema per Zod schema.

import { JSON_SCHEMA_REGISTRY } from '@orpc/zod'

const user = z.object({
  name: z.string(),
  age: z.number(),
})

JSON_SCHEMA_REGISTRY.add(user, {
  examples: [{ name: 'John', age: 20 }],
})
  • Registry entries are merged over the generated schema at any nesting level; direction-specific registries take precedence over the general one, matching v1 behavior.
  • Registries are typed with $input/$output, so examples, default, etc. are checked against the schema's input/output types.

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview, Comment Jul 20, 2026 8:14am

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing dinwwwh:claude/zod-json-schema-registries-3276a9 (fb8d5e3) with main (7106a52)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — added v1-style typed JSON Schema registries to @orpc/zod so users can customize generated schemas, with direction-specific registries taking precedence over the general one.

  • Added JSON_SCHEMA_REGISTRY, JSON_SCHEMA_INPUT_REGISTRY, and JSON_SCHEMA_OUTPUT_REGISTRY backed by Zod's native registry() helper.
  • Updated ZodToJsonSchemaConverter to merge registry entries over generated schemas via Object.assign during toJSONSchema's override callback.
  • Made JsonSchema<Value = any> generic so registry entries can type-check examples/default against a schema's input/output shape.
  • Added runtime tests for merging, direction precedence, and nested-schema application, plus type tests for registry value shapes.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown
More templates

@orpc/arktype

npm i https://pkg.pr.new/middleapi/orpc/@orpc/arktype@1695

@orpc/bun

npm i https://pkg.pr.new/middleapi/orpc/@orpc/bun@1695

@orpc/client

npm i https://pkg.pr.new/middleapi/orpc/@orpc/client@1695

@orpc/cloudflare

npm i https://pkg.pr.new/middleapi/orpc/@orpc/cloudflare@1695

@orpc/contract

npm i https://pkg.pr.new/middleapi/orpc/@orpc/contract@1695

@orpc/experimental-effect

npm i https://pkg.pr.new/middleapi/orpc/@orpc/experimental-effect@1695

@orpc/evlog

npm i https://pkg.pr.new/middleapi/orpc/@orpc/evlog@1695

@orpc/json-schema

npm i https://pkg.pr.new/middleapi/orpc/@orpc/json-schema@1695

@orpc/nest

npm i https://pkg.pr.new/middleapi/orpc/@orpc/nest@1695

@orpc/next

npm i https://pkg.pr.new/middleapi/orpc/@orpc/next@1695

@orpc/openapi

npm i https://pkg.pr.new/middleapi/orpc/@orpc/openapi@1695

@orpc/opentelemetry

npm i https://pkg.pr.new/middleapi/orpc/@orpc/opentelemetry@1695

@orpc/pinia-colada

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pinia-colada@1695

@orpc/pino

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pino@1695

@orpc/publisher

npm i https://pkg.pr.new/middleapi/orpc/@orpc/publisher@1695

@orpc/ratelimit

npm i https://pkg.pr.new/middleapi/orpc/@orpc/ratelimit@1695

@orpc/server

npm i https://pkg.pr.new/middleapi/orpc/@orpc/server@1695

@orpc/shared

npm i https://pkg.pr.new/middleapi/orpc/@orpc/shared@1695

@orpc/tanstack-query

npm i https://pkg.pr.new/middleapi/orpc/@orpc/tanstack-query@1695

@orpc/trpc

npm i https://pkg.pr.new/middleapi/orpc/@orpc/trpc@1695

@orpc/valibot

npm i https://pkg.pr.new/middleapi/orpc/@orpc/valibot@1695

@orpc/zod

npm i https://pkg.pr.new/middleapi/orpc/@orpc/zod@1695

commit: fb8d5e3

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — the follow-up commit added the missing json-schema-typed dependency to @orpc/zod and refreshed pnpm-lock.yaml so the registry types resolve correctly for consumers.

  • Added json-schema-typed@^8.0.2 to packages/zod/package.json.
  • Updated pnpm-lock.yaml with the new importer entry.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit 3826b44 into middleapi:main Jul 20, 2026
11 checks passed
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