I'm trying to validate a query string using JOI and express-validation.
I need the query param ?query[primaryOrgId]=5d2f2c836aeed10026ccba11 to be either a single string or an array of strings, and it is required.
The following schema is validating the primaryOrgId as expected when it is present, but it is not validating that it is required:
index: {
body: {},
query: {
query: {
primaryOrgId: Joi.alternatives().try(
Joi.array().items(Joi.string().regex(mongoId)),
Joi.string().regex(mongoId),
).required()
},
},
options: {
allowUnknownQuery: false,
allowUnknownBody: false,
},
},
I've also tried:
index: {
body: {},
query: {
query: {
primaryOrgId: Joi.alternatives().try(
Joi.array().items(Joi.string().regex(mongoId).required()),
Joi.string().regex(mongoId).required(),
)
},
},
options: {
allowUnknownQuery: false,
allowUnknownBody: false,
},
},
}
How can I ensure that primaryOrgId is present in the query string?