Lon*_*ike 5 javascript jsonschema node.js json-schema-validator ajv
我有一个像这样的 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
};
Run Code Online (Sandbox Code Playgroud)
当我针对此架构运行验证测试时,缺少 object_city 的结果是:
{ keyword: 'required',
dataPath: '',
schemaPath: '#/required',
params: { missingProperty: 'object_city' },
message: 'should have required property \'object_city\'' }
Run Code Online (Sandbox Code Playgroud)
但邮政编码短于 minLength 的结果是:
{ keyword: 'minLength',
dataPath: '.object_zip',
schemaPath: '#/properties/object_zip/minLength',
params: { limit: 5 },
message: 'should NOT be shorter than 5 characters' }
Run Code Online (Sandbox Code Playgroud)
请注意差异:
所以这是我的问题:如何获得一致的错误处理?
| 归档时间: |
|
| 查看次数: |
1016 次 |
| 最近记录: |