我有一个像这样的AJV架构:
// schema.js
module.exports = {
title: 'task',
description: 'A Task Schema',
type: 'object',
properties: {
object_city: {
title: 'City',
type:'string'
},
object_zip: {
title: 'Zip Code',
type: 'string',
maxLength: 5,
minLength: 5
}
},
required: ['object_zip', 'object_city'],
additionalProperties: false
};
当我针对此架构运行验证测试时,缺少object_city的结果是:
{ keyword: 'required',
dataPath: '',
schemaPath: '#/required',
params: { missingProperty: 'object_city' },
message: 'should have required property \'object_city\'' }
但邮政编码短于minLength的结果是:
{ keyword: 'minLength',
dataPath: '.object_zip',
schemaPath: '#/properties/object_zip/minLength',
params: { limit: 5 },
message: 'should NOT be shorter than 5 characters' }
请注意区别:
所以这是我的问题:如何获得一致的错误处理?