Skip to content

fix(zod): preserve null literals in Zod v3 JSON schemas - #2355

Merged
HAYDEN-OAI merged 1 commit into
mainfrom
agent/fix-zod-v3-null-literal
Aug 15, 2026
Merged

HAYDEN-OAI merged 1 commit into
mainfrom
agent/fix-zod-v3-null-literal

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • Handle Zod v3 z.literal(null) before JavaScript's typeof null === 'object' fallback, producing the same { type: 'null', const: null } JSON Schema as Zod v4.
  • Preserve existing OpenAPI 3 compatibility by delegating null literals to the existing parseNullDef implementation.
  • Add focused coverage for all five public Zod helpers, strict and Realtime schemas, local parsing, nested/described/optional/nullable fields, mixed and optimized unions, arrays, defaults, shared definitions, plain null, existing primitive literals, and Zod v4 behavior.

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 affects zodResponseFormat, zodTextFormat, zodFunction, zodResponsesFunction, and zodRealtimeFunction.

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 lint and targeted oxfmt --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.
  • Direct built-package smoke verified all five CommonJS helpers, four local parsers, OpenAPI 3 null compatibility, and the ESM helper.

@openai-sdks

openai-sdks Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 237/237 SDK tests passed in 10.386s for Node SDK PR #2355.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 168ms
tests/chat-completions-create.test.ts ✅ Passed 195ms
tests/chat-completions-stream.test.ts ✅ Passed 194ms
tests/files-content-binary.test.ts ✅ Passed 153ms
tests/files-create-multipart.test.ts ✅ Passed 134ms
tests/files-list-pagination.test.ts ✅ Passed 146ms
tests/initialize-config.test.ts ✅ Passed 172ms
tests/instance-isolation.test.ts ✅ Passed 128ms
tests/models-list.test.ts ✅ Passed 139ms
tests/responses-background-lifecycle.test.ts ✅ Passed 238ms
tests/responses-body-method-errors.test.ts ✅ Passed 282ms
tests/responses-cancel-timeout.test.ts ✅ Passed 189ms
tests/responses-cancel.test.ts ✅ Passed 264ms
tests/responses-compact-retries.test.ts ✅ Passed 228ms
tests/responses-compact.test.ts ✅ Passed 262ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 134ms
tests/responses-create-advanced.test.ts ✅ Passed 202ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.098s
tests/responses-create-errors.test.ts ✅ Passed 198ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 181ms
tests/responses-create-retries.test.ts ✅ Passed 272ms
tests/responses-create-stream-failures.test.ts ✅ Passed 213ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.16s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.628s
tests/responses-create-stream.test.ts ✅ Passed 79ms
tests/responses-create-terminal-states.test.ts ✅ Passed 264ms
tests/responses-create-timeout.test.ts ✅ Passed 197ms
tests/responses-create.test.ts ✅ Passed 142ms
tests/responses-delete.test.ts ✅ Passed 180ms
tests/responses-input-items-errors.test.ts ✅ Passed 191ms
tests/responses-input-items-list.test.ts ✅ Passed 186ms
tests/responses-input-items-options.test.ts ✅ Passed 107ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 242ms
tests/responses-input-tokens-count.test.ts ✅ Passed 219ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.219s
tests/responses-not-found-errors.test.ts ✅ Passed 285ms
tests/responses-parse.test.ts ✅ Passed 189ms
tests/responses-retrieve-retries.test.ts ✅ Passed 235ms
tests/responses-retrieve.test.ts ✅ Passed 255ms
tests/responses-stored-method-errors.test.ts ✅ Passed 537ms
tests/retry-behavior.test.ts ✅ Passed 3.138s
tests/sdk-error-shape.test.ts ✅ Passed 279ms

View OkTest run #31850915668

SDK merge (cc0016653878) · head (4b6e5b539185) · base (a3deafb5f91d) · OkTest (a845fa206fa4)

@jbeckwith-oai jbeckwith-oai 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.

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.

@HAYDEN-OAI
HAYDEN-OAI added this pull request to the merge queue Aug 15, 2026
Merged via the queue into main with commit ed5c5e6 Aug 15, 2026
27 checks passed
@HAYDEN-OAI
HAYDEN-OAI deleted the agent/fix-zod-v3-null-literal branch August 15, 2026 02:18
@openai-sdks openai-sdks Bot mentioned this pull request Aug 15, 2026

This branch was previously deployed

1 inactive deployment
ci — 4b6e5b53 Deployed Aug 14, 2026 by HAYDEN-OAI via ecosystem tests #7868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants