AJVvalidation:数据path不一致
我有一个像这样的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 };
当我对这个模式运行我的validationtesting时,丢失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' }
请注意差异:
- 所需的返回validation失败一个空的 dataPath ,但在minLength上的validation失败返回“.object_zip”作为dataPath
- 无效validation所需返回'#/ required'为schemaPath ,minLengthvalidation失败则返回'#/ properties / object_zip / minLength'作为schemaPath
所以这里是我的问题:我如何获得一致的error handling?