Joi 验证未验证必填字段

问题描述

我尝试使用 Joi 验证 4 个字段。我希望满足以下要求:Either firstsecondAnd thirdfourth。>

所以以下之一应该通过但没有其他应该:

{first: 'yo',third: true}
// or
{second: 'bro',third: true}
// or
{first: 'yo',fourth: true}
// or
{second: 'bro',fourth: true}

我尝试了以下操作,但它让 thirdfourth 为空。

function validate(data) {
    const schema = Joi.object({
        first: Joi.string(),second: Joi.string(),third: Joi.boolean(),fourth: Joi.boolean(),})
        .xor('first','second')
        .xor('third','fourth');

    return schema.validate(data);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)