How to allow any other key in Joi
The correct answer is actually to use object.unknown(true)
.
const schema = Joi.object().keys({
a: Joi.string().required(),
b: Joi.string().required()
}).unknown(true);
You can add unknown keys using object.pattern(regex, schema) this way IF you want to make sure these unknown keys are strings:
const schema = Joi.object().keys({
a: Joi.string().required(),
b: Joi.string().required()
}).pattern(/./, Joi.string());
For a general pass of all key types use object.unknown(true):
const schema = Joi.object().keys({
a: Joi.string().required(),
b: Joi.string().required()
}).unknown(true);