我一直在尝试在我们的节点应用程序中实现 Joi(joi 作为独立的,而不是与 hapi 一起),它似乎正确验证了模式,但错误总是相同的
[ValidationError: value must be an object]
name: 'ValidationError',
details:
[ { message: 'value must be an object',
path: 'value',
type: 'object.base',
context: [Object] } ],
_object:.....
Run Code Online (Sandbox Code Playgroud)
我从来没有得到关于哪个键失败的具体信息以及失败原因的描述。
这是我正在使用的示例架构:
exports.workersSchema =
{
workers: joi.array({
id: joi.string().alphanum(),
wID: joi.object({
idValue: joi.string().alphanum()
}),
person: {
governmentIDs: joi.array({itemID: joi.string().alphanum()}),
legalName: joi.object({
givenName: joi.string(),
middleName: joi.string(),
preferredSalutations: joi.array(
{
salutationCode: {
longName: joi.string()
}
}
),
preferredName: joi.object().keys({
FormattedName: joi.string()
}),
}),
birthDate: joi.string().alphanum()
}
})
}
Run Code Online (Sandbox Code Playgroud)
这是我要发送的 json 对象: …