MCPcopy
hub / github.com/colinhacks/zod / unionProcessor

Function unionProcessor

packages/zod/src/v4/core/json-schema-processors.ts:336–352  ·  view source on GitHub ↗
(schema, ctx, json, params)

Source from the content-addressed store, hash-verified

334};
335
336export 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
354export const intersectionProcessor: Processor<schemas.$ZodIntersection> = (schema, ctx, json, params) => {
355 const def = schema._zod.def as schemas.$ZodIntersectionDef;

Callers

nothing calls this directly

Calls 1

processFunction · 0.90

Tested by

no test coverage detected