MCPcopy Create free account
hub / github.com/json-editor/json-editor / validateUnion

Function validateUnion

docs/scripts/ajv-validator.js:5543–5567  ·  view source on GitHub ↗
(cxt)

Source from the content-addressed store, hash-verified

5541 }
5542 exports.validateArray = validateArray;
5543 function validateUnion(cxt) {
5544 const { gen, schema, keyword, it } = cxt;
5545 /* istanbul ignore if */
5546 if (!Array.isArray(schema))
5547 throw new Error("ajv implementation error");
5548 const alwaysValid = schema.some((sch) => (0, util_1.alwaysValidSchema)(it, sch));
5549 if (alwaysValid && !it.opts.unevaluated)
5550 return;
5551 const valid = gen.let("valid", false);
5552 const schValid = gen.name("_valid");
5553 gen.block(() => schema.forEach((_sch, i) => {
5554 const schCxt = cxt.subschema({
5555 keyword,
5556 schemaProp: i,
5557 compositeRule: true,
5558 }, schValid);
5559 gen.assign(valid, (0, codegen_1._) `${valid} || ${schValid}`);
5560 const merged = cxt.mergeValidEvaluated(schCxt, schValid);
5561 // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
5562 // or if all properties and items were evaluated (it.props === true && it.items === true)
5563 if (!merged)
5564 gen.if((0, codegen_1.not)(valid));
5565 }));
5566 cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
5567 }
5568 exports.validateUnion = validateUnion;
5569//# sourceMappingURL=code.js.map
5570

Callers

nothing calls this directly

Calls 10

letMethod · 0.80
blockMethod · 0.80
subschemaMethod · 0.80
assignMethod · 0.80
mergeValidEvaluatedMethod · 0.80
resultMethod · 0.80
resetMethod · 0.80
errorMethod · 0.80
nameMethod · 0.45
ifMethod · 0.45

Tested by

no test coverage detected