UNPKG

717 BPlain TextView Raw
1import type {CodeKeywordDefinition, AnySchema} from "../../types"
2import type {KeywordCxt} from "../../compile/validate"
3import {alwaysValidSchema} from "../../compile/util"
4
5const 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
22export default def