I want to validate object using Joi which inovle use of Joi.ref() with multiplication operation.
var object = {
    a: 5,
    b: 6
}
// this is wrong as Joi.ref('a')*2 is now allowed in max()
var schema = Joi.object({
    a: Joi.number().integer(),
    b: Joi.number().integer().min(1).max(Joi.ref('a')*2)
})
Joi.ref('a')*2 is not allowed. So how can I validate object such that b<=2*a?
Using adjust option
var schema = Joi.object({
    a: Joi.number().integer(),
    b: Joi.number().integer().min(1).max(Joi.ref('a', {
      adjust: (value) => value * 2
    }))
})
stackblitz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With