Javascript Joi验证和多重条件

Javascript Joi验证和多重条件,javascript,hapijs,joi,Javascript,Hapijs,Joi,我试图在以下条件下验证我的目标对象: if (target.company === `GP` AND one of target.documents type equals `full`) { one of target.documents type must equals `part-should-be-error` } else { throw new Error() } 在本例中,验证不会返回任何错误,但它应该返回,因为'part'!='零件应为错误“ 我试过了,但是Jo

我试图在以下条件下验证我的
目标
对象:

if (target.company === `GP` AND one of target.documents type equals `full`) {
    one of target.documents type must equals `part-should-be-error`
} else {
    throw new Error()
}
在本例中,验证不会返回任何错误,但它应该返回,因为
'part'!='零件应为错误“

我试过了,但是Joi v15不起作用

由于我无法将数组模式与替代模式合并,所以我所能做的就是使用
$
来获取全局
上下文,但它似乎也不起作用

我有基于Joi v15.1.1的代码库,所以请安装相同的版本
npm i@hapi/joi@15.1.1

const-Joi=require('@hapi/Joi');
(异步()=>{
常数目标={
姓名:“杰夫”,
公司:“GP”,
文件:[
{type:'full',value:'apple'},
{类型:'part',值:'tesla'},
],
};
const documents=Joi.object().keys({
类型:Joi.string().valid(['full','part','empty']),
值:Joi.string().min(1).max(40)
.required(),
}).required();
const schema=Joi.object()
.钥匙({
名称:Joi.string().min(1).max(20)
.required(),
公司:Joi.string().valid(['GP','QW']),
文档:Joi.array().items(documents).min(1)
。当(“$”{
is:Joi.object().keys({
公司:Joi.string().valid(['GP']),
文档:Joi.array().has(Joi.object({type:Joi.string().valid('full'))}.unknown().required()),
}).unknown().required(),
然后:Joi.array().has(Joi.object({type:Joi.string().valid(['part-should-be-error'])))}.unknown()).required(),
})
.required(),
});
wait Joi.validate(目标,模式,{context:target});
})();
如果我做了一些奇怪的事情,请随意展示另一种解决方法