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 ?
Here is an example of two extensions for the number base type. The first extension loses its language definition.
After tracing the code, this seems to happen because language definitions are merged using Object.assign. Maybe something like lodash.merge would be more appropriate?
constBaseJoi=require('joi');constAssert=require('assert');constExtendedJoi=BaseJoi.extend(function(joi){return{base: joi.number(),name: 'number',language: {greaterThan10: `Must be > 10`},rules: [{name: `greaterThan10`,validate(params,value,state,options){returnvalue>10
? value
: this.createError(`number.greaterThan10`,{v: value},state,options)}}]}},function(joi){return{base: joi.number(),name: 'number',language: {greaterThan20: `Must be > 20`},rules: [{name: `greaterThan20`,validate(params,value,state,options){returnvalue>20
? value
: this.createError(`number.greaterThan20`,{v: value},state,options)}}]}});constschema=ExtendedJoi.number().greaterThan10().greaterThan20();// Passes both rulesAssert.equal(schema.validate(30).value,30);// Failed second rule - message is OKAssert.equal(schema.validate(15).error.message,'"value" Must be > 20');// Failed first rule - can't use it's languageAssert.equal(schema.validate(5).error.message,'Error code "number.greaterThan10" is not defined, your custom type is missing the correct language definition');
Which result you had ?
The first extension lost its language definition.
What did you expect ?
Both extension would work as expected
The text was updated successfully, but these errors were encountered:
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
lockbot
locked as resolved and limited conversation to collaborators
Jan 9, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Context
What are you trying to achieve or the steps to reproduce ?
Here is an example of two extensions for the
number
base type. The first extension loses its language definition.After tracing the code, this seems to happen because language definitions are merged using
Object.assign
. Maybe something likelodash.merge
would be more appropriate?Which result you had ?
The first extension lost its language definition.
What did you expect ?
Both extension would work as expected
The text was updated successfully, but these errors were encountered: