0

I am Using @hapi/joi. I have an array which store value dynamically, it store string, empty string (an empty array) or an Objects ({"userid": "111jh2jh322j3h2j3h", "msg": 1}).

So it will be like this:

type1-> member: []
type2-> member: ["firstString", "secondString"]
type3-> member: [{"userid": "111jh2jh322j3h2j3h", "msg": 1}, {"userid": "7875jh2jh3545hj3hth", "msg": 0}]

I am confused that how to do validation on @Hapi/joi.

Currently My implementation is:

member: Joi.array().items(Joi.string().allow('')),

I know that If we have an object which is stored under an array then I will do the validation is like:

member: Joi.array().items(Joi.object({
      userid: Joi.string(),
      msg: Joi.number(),
    })),

Any help is really appreciated for that. Thanks in advance.

Aks
  • 1,092
  • 3
  • 12
  • 29

1 Answers1

0

It will be like this:

member: Joi.array().items(Joi.string().allow(''), Joi.object({
        userid: Joi.string(),
        msg: Joi.number(),
      })),
Aks
  • 1,092
  • 3
  • 12
  • 29