You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to achieve or the steps to reproduce ?
Hi,
I'm used to have several versions of my validation schemas, each new version being based on the previous one. In the bellow example, I have schema a and schema b, b being based on a. I use the .concat() to achieve that.
In my example, I redefine the test .min() by changing the limit value from 1 (schema a) to 0 (schema b).
consta=joi.object({customFields: joi.object().min(1),});constb=a.concat(joi.object({customFields: joi.object().min(0),}),);// tests against schema a// 1. should failjoi.validate({customFields: {}},a,(err)=>{if(err){console.info('OK: test 1 should fail and it did.');// console.error(err);}else{console.info('NOT OK: test 1 should fail but it did not.');}});// 2. should passjoi.validate({customFields: {hello: 'hi'}},a,(err)=>{if(err){console.info('NOT OK: test 2 should pass but it did not.');// console.error(err);}else{console.info('OK: test 2 should pass and it did.');}});// tests against schema b// 3. should passjoi.validate({customFields: {}},b,(err)=>{if(err){console.info('NOT OK: test 3 should pass but it did not.');console.error(err);}else{console.info('OK: test 3 should pass and it did.');}});
Which result you had ?
OK: test1shouldfailanditdid.OK: test2shouldpassanditdid.NOT OK: test3shouldpassbutitdidnot.{ ValidationError: child"customFields"failsbecause["customFields"musthaveatleast1children]atObject.exports.process(/home/hidden_path/node_modules/@hapi/joi/lib/errors.js:202:19)atinternals.Object._validateWithOptions(/home/hidden_path/node_modules/@hapi/joi/lib/types/any/index.js:762:31)atmodule.exports.internals.Any.root.validate(/home/hidden_path/node_modules/@hapi/joi/lib/index.js:145:23)atObject.<anonymous>(/home/hidden_path/joitest.js:44:5)atModule._compile(module.js:643:30)atObject.Module._extensions..js(module.js:654:10)atModule.load(module.js:556:32)attryModuleLoad(module.js:499:12)atFunction.Module._load(module.js:491:3)atFunction.Module.runMain(module.js:684:10)
isJoi: true,name: 'ValidationError',details:
[{message: '"customFields" must have at least 1 children',path: [Array],type: 'object.min',context: [Object]}],_object: {customFields: {}},annotate: [Function]}
What did you expect ?
I expected the .min() test to be correctly redefined and test 3 to pass.
The text was updated successfully, but these errors were encountered:
Context
What are you trying to achieve or the steps to reproduce ?
Hi,
I'm used to have several versions of my validation schemas, each new version being based on the previous one. In the bellow example, I have schema
a
and schemab
,b
being based ona
. I use the.concat()
to achieve that.In my example, I redefine the test
.min()
by changing the limit value from 1 (schemaa
) to 0 (schemab
).Which result you had ?
What did you expect ?
I expected the
.min()
test to be correctly redefined and test 3 to pass.The text was updated successfully, but these errors were encountered: