0

我想分配 required 或者client_id如果client_secret这些属性之一不为空,我必须签入 Joi 分配它required Joi我该如何检查

schema = Joi.Object().keys({
    account_id: Joi.string().required(),
    client_id: Joi.string(),   // in client_id or client_secret //
    client_secret: Joi.string() // one must be required I have to check for This in Joi
});
4

1 回答 1

0

您可以使用object.or来解决此问题

schema = Joi.Object().keys({
    account_id: Joi.string().required(),
    client_id: Joi.string(),   // in client_id or client_secret //
    client_secret: Joi.string() // one must be required I have to check for This in Joi
}).or('client_id', 'client_secret');
于 2016-09-22T05:09:34.473 回答