简体   繁体   中英

Joi require at least one of a group of keys when a specific key exists

Given the example:

Joi.object({
  a: Joi.string(),
  b: Joi.string(),
  c: Joi.string(),
})

I want that when key A is filled, keys B and C are required at least one of them:

{ a: 'foo', b: 'bar' } //success
{ a: 'foo', c: 'bar' } //success
{ a: 'foo' } #error

You can require a minimum count of keys on the object.

Joi.object({
  a: Joi.string(),
  b: Joi.string(),
  c: Joi.string(),
}).min(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM