我在我的反对模型中使用这个 jsonSchema:
static get jsonSchema() {
return {
type: 'object',
required: ['firstName', 'lastName'],
properties: {
id: { type: 'integer' },
parentId: { type: ['integer', 'null'] },
firstName: { type: 'string', minLength: 1, maxLength: 255 },
lastName: { type: 'string', minLength: 1, maxLength: 255 },
date: {type: 'unexisting-type'},
age: { type: 'number' },
}
};
}
您可以看到date是 AJV 验证无法识别的类型(由 Objection.js 使用)。但是,插入以下数据时,插入操作返回成功:
{
"firstName":"sample",
"lastName":"sample",
"date":"2018-12-21 10:20"
}
为什么 AJV 在创建模式时没有返回验证错误?
我在一个最小的 JSFiddle 示例中进行了测试,它确实返回了一个错误(AJV v6.6.2) https://jsfiddle.net/ads80y5j/
我正在使用 Objection v1.4.0(使用 AJV v^6.1.1)