如何对以下内容进行@hapi/joi 验证?

How to do @hapi/joi validation for the following?

在下面的模式中,我需要像,如果类型是 withdraw => [name,accountNumber,ifscCode,branchName,comments,upiId,amount,bonus,userId] 来传递 但如果类型是存款,我需要 => [txnReferenceId,amount,bonus,userId] 才能通过。

    const withdrawDepositValidatorSchema = Joi.object({
        type: Joi.string(),
        name: Joi.string(),
        accountNumber: Joi.number(),
        ifscCode: Joi.string().alphanum(),
        branchName: Joi.string(),
        comments: Joi.string(),
        upiId: Joi.string(),
        txnReferenceId: Joi.number(),
        amount: Joi.number(),
        bonus: Joi.number(),
        userId: Joi.string()
    })

您可以使用 when 条件。我在这里举了一个例子,但也可以用于其他领域。

const withdrawDepositValidatorSchema = Joi.object({
  type: Joi.string(),
  name: Joi.when(Joi.ref("type"), {
    "is": Joi.string().valid("Withdraw"),
    "then": Joi.string(),
    "otherwise": Joi.forbidden()
  }),