0

I want to validation the datatype like an array in javascript.

the origin data like:

"dams":[
{"id": 1, "name": "Burrinjuck Dam", "self": "",…},
{"id": 2, "name": "Blowering Dam", "self": "",…}
]

The number of elements is not sure, but each element is the same type of dam object. Do Joi provider any method to validate a list of same type elements?

user504909
  • 9,119
  • 12
  • 60
  • 109

1 Answers1

0

You can combine Joi.array().items() with Joi.object(), and do something like this:

const schema = Joi.object({
   damns: Joi.array().items(
       Joi.object().keys({
             id: Joi.string(),
             name: Joi.string(),
             self: Joi.string()
       })
   )
});
soltex
  • 2,993
  • 1
  • 18
  • 29