2

Struggling to find anything about this in the docs - is it possible to reference multiple values?

Say I have a schema that takes 3 numbers (a, b, c), is it possible to set a max property on c based on a and b. Something like the following:

joi.object().keys({
  a: joi.number(),
  b: joi.number(),
  c: joi.number().max(joi.ref('a') + joi.ref('b'))
})
JmJ
  • 1,767
  • 2
  • 26
  • 46

1 Answers1

0

For reference, multiple values use expression like

const schema = joi.object().keys({
  a: joi.number(),
  b: joi.number(),
  c: joi.expression("{{a +b}}"),
});
console.log(schema.validate({ a: 400, b: 300, c: 700 }));
Mohammad Ali Rony
  • 4,066
  • 2
  • 17
  • 29