Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Joi validation types

I search a lot but nothing found to allow multiple type validation in Joi

Link: https://github.com/hapijs/joi

I would like to use something like this:

validate: {
    type: joi.or([
        joi.string(),
        joi.array(),
    ])
};
like image 646
Mr.Orange Avatar asked Jan 04 '17 16:01

Mr.Orange


1 Answers

Try:

validate: {
    type: joi.alternatives().try(joi.string(), joi.array())
}

or:

validate: {
    type: [joi.string(), joi.array()]
}

See: https://github.com/hapijs/joi/blob/v10.1.0/API.md#alternatives

like image 61
rsp Avatar answered Sep 20 '22 18:09

rsp