I am validating a GET request query string (using express-joi-validation) and require the user to pass at least one extra key value pair not directly specified in the schema.
I have tried to validate as follows:
const schema = Joi
.object({
requiredKey: Joi.string().required()
knownExtraKey: Joi.boolean()
})
.pattern(/^/, Joi.string().required())
schema.validate({requiredKey: 'A'}) // valid but shouldn't be
schema.validate({requiredKey: 'A', name: "paul"}) // valid
.pattern()is supposed to take two parameters like that? If you search the documentation for "nested", you'll see that the property constraints are defined within an object passed tokeys({}). I've never used Joi, so that's just my quick read for something else you could try. - Marc.pattern(/^/, Joi.string().valid('onlythis'))and validate object{a : 1}I will get a validation error as expected so I believe my usage of .pattern is correct - Batters