Skip to content

fix: replace z.undefined() with z.never() for JSON Schema compat#1075

Merged
notgitika merged 1 commit intomainfrom
fix/zod-json-schema-compat
May 1, 2026
Merged

fix: replace z.undefined() with z.never() for JSON Schema compat#1075
notgitika merged 1 commit intomainfrom
fix/zod-json-schema-compat

Conversation

@notgitika
Copy link
Copy Markdown
Contributor

Summary

Fixes Zod JSON Schema generation failure: z.undefined() cannot be represented in JSON Schema.

The AB test variant XOR union used z.undefined().optional() to exclude the alternate field. Replace with z.never().optional() which Zod can serialize.

Test plan

  • npm run build passes
  • node scripts/generate-schema.mjs succeeds

@notgitika notgitika requested a review from a team May 1, 2026 00:18
@github-actions github-actions Bot added size/xs PR size: XS agentcore-harness-reviewing AgentCore Harness review in progress labels May 1, 2026
@agentcore-cli-automation
Copy link
Copy Markdown

LGTM. The change is minimal and correct:

  • z.undefined() has no JSON Schema representation in Zod v4's z.toJSONSchema(), which is why generate-schema.mjs was failing.
  • z.never().optional() serializes cleanly (as { "not": {} } on an optional property) and preserves the XOR semantics: the field must be absent/undefined, and any defined value is rejected on the inner schema. Combined with the union, an object with both fields set fails both branches, so mutual exclusivity still holds.
  • No need to regenerate schemas/agentcore.schema.v1.json in this PR — the repo's release workflow regenerates it, and direct edits to schemas/ are rejected by CI outside release PRs.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 42.89% 8936 / 20830
🔵 Statements 42.17% 9485 / 22491
🔵 Functions 39.66% 1537 / 3875
🔵 Branches 39.82% 5769 / 14486
Generated in workflow #2262 for commit 37846f6 by the Vitest Coverage Report Action

@notgitika notgitika force-pushed the fix/zod-json-schema-compat branch from 4d8bfe1 to 84a7b47 Compare May 1, 2026 00:24
@github-actions github-actions Bot added size/xs PR size: XS and removed size/xs PR size: XS labels May 1, 2026
padmak30
padmak30 previously approved these changes May 1, 2026
@notgitika notgitika force-pushed the fix/zod-json-schema-compat branch from 84a7b47 to 03c7a0c Compare May 1, 2026 00:27
@github-actions github-actions Bot added size/s PR size: S and removed size/xs PR size: XS labels May 1, 2026
@notgitika notgitika force-pushed the fix/zod-json-schema-compat branch from 03c7a0c to 37846f6 Compare May 1, 2026 00:32
@github-actions github-actions Bot added size/s PR size: S and removed size/s PR size: S labels May 1, 2026
@notgitika notgitika merged commit eab8c87 into main May 1, 2026
22 checks passed
@notgitika notgitika deleted the fix/zod-json-schema-compat branch May 1, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants