| 1 | import type {CodeKeywordDefinition, AnySchema} from "../../types" |
| 2 | import type {KeywordCxt} from "../../compile/validate" |
| 3 | import {alwaysValidSchema} from "../../compile/util" |
| 4 | |
| 5 | const def: CodeKeywordDefinition = { |
| 6 | keyword: "allOf", |
| 7 | schemaType: "array", |
| 8 | code(cxt: KeywordCxt) { |
| 9 | const {gen, schema, it} = cxt |
| 10 | /* istanbul ignore if */ |
| 11 | if (!Array.isArray(schema)) throw new Error("ajv implementation error") |
| 12 | const valid = gen.name("valid") |
| 13 | schema.forEach((sch: AnySchema, i: number) => { |
| 14 | if (alwaysValidSchema(it, sch)) return |
| 15 | const schCxt = cxt.subschema({keyword: "allOf", schemaProp: i}, valid) |
| 16 | cxt.ok(valid) |
| 17 | cxt.mergeEvaluated(schCxt) |
| 18 | }) |
| 19 | }, |
| 20 | } |
| 21 | |
| 22 | export default def |