(cxt: KeywordCxt)
| 133 | } |
| 134 | |
| 135 | export function validateUnion(cxt: KeywordCxt): void { |
| 136 | const {gen, schema, keyword, it} = cxt |
| 137 | /* istanbul ignore if */ |
| 138 | if (!Array.isArray(schema)) throw new Error("ajv implementation error") |
| 139 | const alwaysValid = schema.some((sch: AnySchema) => alwaysValidSchema(it, sch)) |
| 140 | if (alwaysValid && !it.opts.unevaluated) return |
| 141 | |
| 142 | const valid = gen.let("valid", false) |
| 143 | const schValid = gen.name("_valid") |
| 144 | |
| 145 | gen.block(() => |
| 146 | schema.forEach((_sch: AnySchema, i: number) => { |
| 147 | const schCxt = cxt.subschema( |
| 148 | { |
| 149 | keyword, |
| 150 | schemaProp: i, |
| 151 | compositeRule: true, |
| 152 | }, |
| 153 | schValid |
| 154 | ) |
| 155 | gen.assign(valid, _`${valid} || ${schValid}`) |
| 156 | const merged = cxt.mergeValidEvaluated(schCxt, schValid) |
| 157 | // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true) |
| 158 | // or if all properties and items were evaluated (it.props === true && it.items === true) |
| 159 | if (!merged) gen.if(not(valid)) |
| 160 | }) |
| 161 | ) |
| 162 | |
| 163 | cxt.result( |
| 164 | valid, |
| 165 | () => cxt.reset(), |
| 166 | () => cxt.error(true) |
| 167 | ) |
| 168 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…