-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
- node version: v10.14.0
- joi version: 15.0.3
- environment: node
- used with: standalone
What are you trying to achieve or the steps to reproduce ?
const Joi = require('@hapi/joi');
const regex = /^foobar$/i; //case-insensitive match!
const schema1 = Joi.object().keys({
fooBar: Joi.string().required()
}).rename(regex, 'fooBar');
const schema2 = Joi.object().keys({
fooBar: Joi.string().required()
}).rename(regex, 'fooBar', { override: true });
const handler = (err, val) => {
if (err) return console.error(err);
console.log(val);
};
console.log('1. ---------------------');
schema1.validate({ FooBar: 'a'}, handler);
console.log('2. ---------------------');
schema1.validate({ fooBar: 'a'}, handler);
console.log('3. ---------------------');
schema2.validate({ FooBar: 'a'}, handler);
console.log('4. ---------------------');
schema2.validate({ fooBar: 'a'}, handler);Which result you had ?
- { fooBar: 'a' }
- ValidationError: '"value" cannot rename children [fooBar] because override is disabled and target "fooBar" exists' (type: 'object.rename.regex.override')
- { fooBar: 'a' }
- ValidationError: '"fooBar" is required' (type: 'any.required')
The validation is successful, when FooBar field is passed, but fails every time, when I pass object with field fooBar.
What did you expect ?
I want to define a schema, that accepts fields case insensitively, e.g. I want to generate { fooBar: 'a' } output from every of the following inputs without failure:
{ fooBar: 'a' }{ FooBar: 'a' }{ FoOBaR: 'a' }
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect