| 334 | }; |
| 335 | |
| 336 | export const unionProcessor: Processor<schemas.$ZodUnion> = (schema, ctx, json, params) => { |
| 337 | const def = schema._zod.def as schemas.$ZodUnionDef; |
| 338 | // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches) |
| 339 | // This includes both z.xor() and discriminated unions |
| 340 | const isExclusive = def.inclusive === false; |
| 341 | const options = def.options.map((x, i) => |
| 342 | process(x, ctx as any, { |
| 343 | ...params, |
| 344 | path: [...params.path, isExclusive ? "oneOf" : "anyOf", i], |
| 345 | }) |
| 346 | ); |
| 347 | if (isExclusive) { |
| 348 | json.oneOf = options; |
| 349 | } else { |
| 350 | json.anyOf = options; |
| 351 | } |
| 352 | }; |
| 353 | |
| 354 | export const intersectionProcessor: Processor<schemas.$ZodIntersection> = (schema, ctx, json, params) => { |
| 355 | const def = schema._zod.def as schemas.$ZodIntersectionDef; |