我正在使用节点 9.2.0 和 ajv 6.0.0。
我有一个模式,我希望在其上使用否定的lookbehind,它的定义如下:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "release format",
"description": "A Release Format",
"type": "object",
"properties": {
"id": {"type": "integer"},
"title": {
"anyOf": [
{
"type": "string",
"pattern": "^((?!itunes).)*$"
},
{
"type": "string",
"pattern": "^((?!exclusive).)*$"
},
{
"type": "string",
"pattern": "^((?!ringtone).)*$"
}
]
}
}
}
但是,似乎当我尝试使用以下数据通过 AJV 验证这一点时:{"id": 123, "title": "world exclusive"}
我没有收到验证错误。
编码:
const Ajv = require('ajv');
class Validator {
constructor() {
this.releaseFormatSchema = JSON.parse(fs.readFileSync('./schemas/release-format.json'));
this.schemaValidator = new Ajv({allErrors: true});
}
validate(data) {
let validate = this.schemaValidator.compile(this.releaseFormatSchema);
let valid = validate(data);
console.log(valid);
console.log(validate);
}
}
数据在哪里:{"id": 123, "title": "world exclusive"}
. 我希望这会出错,但它目前告诉我数据是有效的。