我正在使用 ajv-errors 探索 Ajv,以验证 json 模式并生成自定义错误消息。一切正常,但我无法为单个值的类型设置自定义错误消息。
const emailSchema = {
type: 'object',
required: ['foo', 'bar', 'car'],
properties: {
foo: { type: 'integer' },
bar: { type: 'string' },
car: { type: 'string' }
},
errorMessage: {
type: 'should be an object',
required: {
foo: 'foo field is missing',
bar: 'bar field is missing',
car: 'car field is missing'
}
}
};
Run Code Online (Sandbox Code Playgroud)
输出跟随误差
[
{
"keyword": "type",
"dataPath": "/foo",
"schemaPath": "#/properties/foo/type",
"params": {
"type": "integer"
},
"message": "should be integer"
}, …Run Code Online (Sandbox Code Playgroud)