Repository navigation
fix(zod): preserve null literals in Zod v3 JSON schemas - #2355
Merged
Merged
Conversation
Contributor
jbeckwith-oai
approved these changes
Aug 14, 2026
jbeckwith-oai
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the full exact-head diff in two passes. The null-literal guard is placed at the canonical Zod v3 parser boundary, preserves the other literal branches, reuses the existing OpenAPI null parser, and is covered across all public helpers plus nested/reference/target and Zod v4 compatibility paths. Strict thermo and test-policy review are clean, and all applicable exact-head CI is green. No findings.
Merged
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
z.literal(null)before JavaScript'stypeof null === 'object'fallback, producing the same{ type: 'null', const: null }JSON Schema as Zod v4.parseNullDefimplementation.Why
The current converter emits
{ type: 'object' }for Zod v3 null literals. Consequently, the model-visible schema rejects actual null while the local Zod validator rejects every object accepted by that schema. This affectszodResponseFormat,zodTextFormat,zodFunction,zodResponsesFunction, andzodRealtimeFunction.The regression-first run on unmodified main produced 10 failing / 6 passing dedicated tests, including independent failures for all five helpers.
Verification
./node_modules/.bin/vitest run --config vitest.config.mts tests/helpers/zod.test.ts tests/helpers/zod-null-literal.test.ts— 58 passed.pnpm test:unit— 2,106 passed across 71 handwritten test files.pnpm lintand targetedoxfmt --check— passed.pnpm exec tsc— passed.pnpm build— passed for CommonJS and ESM../node_modules/typescript-4-9/bin/tsc --project dist/src/tsconfig.json --noEmit— passed../node_modules/typescript/bin/tsc --project dist/src/tsconfig.json --noEmit— passed.node --experimental-strip-types scripts/test-packed-package.ts— packed CommonJS/ESM artifact and both TypeScript generations passed across 1,200 source maps.