Skip to content

fix(v4): handle if/then/else validation in json-schema - #6377

Open
mauri870 wants to merge 3 commits into
colinhacks:mainfrom
mauri870:fix/json-schema-if
Open

mauri870 wants to merge 3 commits into
colinhacks:mainfrom
mauri870:fix/json-schema-if

Conversation

@mauri870

Copy link
Copy Markdown

This PR implements if/then/else conditionals from the JSON Schema specification.

dependentRequired and dependentSchemas are not yet implemented.

…fromJSONSchema

When all branches of a oneOf share a common `properties.X.const` discriminator
(directly or inside an allOf), replace z.xor with a superRefine that validates
the discriminator field first. Invalid discriminator values now report a precise
error at that field listing all valid options:

  [invalid_value] at type: expected "elasticsearch" | "s3" | "debug" | …

rather than the generic `[invalid_union]: Invalid input` at the oneOf level.
Falls back to z.xor for oneOf schemas without a detectable common discriminator.

This branch was successfully deployed

1 active deployment
Preview – zod-v4 — f1af82f5 Deployed Aug 21, 2026 by vercel[bot]
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