https://ajv.js.org/guide/user-keywords.html
ajv关键字,例如
- type
- properties
- minLength
关键字特点:验证数据是否符合某些规则
ajv.addKeyword({keyword: "range",type: "number",schemaType: "array",implements: "exclusiveRange",compile: ([min, max], parentSchema) =>parentSchema.exclusiveRange === true? (data) => data > min && data < max: (data) => data >= min && data <= max,})const schema = {range: [2, 4], exclusiveRange: true}const validate = ajv.compile(schema)console.log(validate(2.01)) // trueconsole.log(validate(3.99)) // trueconsole.log(validate(2)) // falseconsole.log(validate(4)) // false
Meta-schemas
https://ajv.js.org/options.html#meta
http://json-schema.org/specification.html
