Open nlundquist opened 4 years ago
@nlundquist What exactly was the error?
It's a validation error due to the argsByName
key being present at extension.rules.bar.argsByName
. That key is added by Joi during the first call to .extend
: https://github.com/sideway/joi/blob/9cffab90039c313ca62d473d01993b492dd4d007/lib/extend.js#L111
@nlundquist Thanks, I can verify this.
We recently ran into this problem when we tried using rewire
on a module where we used a single Joi.extend
call. The module was probably require
d by other modules in addition to this rewire
so the same extension was being registered twice. The second result in this "rules.compare.argsByName" is not allowed
error while rewiring our module.
I second that:
What result did you expect?
For extension objects to be reusable without errors. Extend seems as if it should not have side effects on the extension objects passed.
It's usually assumed that people are using the modern way of writing extensions, that is with a factory function, but you're right that it shouldn't modify the args anyway.
Context
What are you trying to achieve or the steps to reproduce?
Trying to pass an extension object instance (rather than a generator function) to Joi twice results in a validation error due to a modification made by Joi.
What was the result you got?
Validation error.
What result did you expect?
For extension objects to be reusable without errors. Extend seems as if it should not have side effects on the extension objects passed.