| 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 | |