allOf.ts 717 B

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