【发布时间】:2019-10-15 07:43:18
【问题描述】:
我正在尝试将 AJV 与以下代码一起使用,当我验证具有多个错误的对象时,AJV 一次只抛出一个错误。
const schema = {
type: 'object',
properties: {
name: {type: 'string', minLength: 1, maxLength: 1},
sku: { type: 'string', minLength: 1, maxLength: 200},
},
required: ['name', 'sku']
}
const ajv = require('ajv');
const validator = new ajv();
const valid = validator.validate(schema, {});
if (!valid) {
console.log(validator.errors);
}
[ { keyword: 'required',
dataPath: '',
schemaPath: '#/required',
params: { missingProperty: 'name' },
message: 'should have required property \'name\'' } ]
【问题讨论】:
标签: javascript node.js ecmascript-6 ajv