-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct way to write an "identity" extension? #1000
Comments
Not sure I understand, identity is joi.any() for me. |
No, what I mean is that I want to write an extension that would be a "copy" On Thu, Oct 6, 2016, 12:33 Nicolas Morel notifications@github.com wrote:
|
I'll wait for your example to see if there's anything wrong with type overriding, I think it's tested. |
Ok, will post it soon. On Fri, Oct 7, 2016, 02:23 Nicolas Morel notifications@github.com wrote:
|
Here is a minimal example. This validation fails with
But this one succeeds (line 2 commented out):
I assumed the new |
@Marsup But maybe I'm just doing something wrong, and this is not the correct way to write a "copy" of |
You're using an api that's a shorthand to |
Oh, so when specifying |
Just use |
Oh, so it's only special features of the constructor that don't get carried over. Now I understand, and I can easily work around this. Thanks! I'm satisfied and could close this issue as for me, but you said you'd maybe implement this in the future, so perhaps you want to keep it open? |
Indeed this could be an interesting feature so I'll keep this open. Even mark it as open for contributors. |
Do you intent to support it? If so, I can try to send a PR to add the option to pass arguments to custom extensions. |
Arguments are in my plans but it needs careful design because of inheritance, I didn't have time to think about it so far. |
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. |
(by "identity" I mean "one that changes nothing", similar to the identity function)
Context
What are you trying to achieve or the steps to reproduce ?
I'm trying to do a minimal "identity" extension to joi that would replace an existing data type, but not change it in any way, so I'm using it as the base.
Which result you had ?
joi.object() seems to be behaving slightly differently, it has something to do with
.options()
and.keys()
andallowUnknown
changing their behavior. I will construct a minimal example demonstrating this if it's not obvious what I'm doing wrong.What did you expect ?
I expected the new joi.object() to work exactly as before, and change nothing in how the new joi object behaves. Was that assumption correct? Is this how you would write an "identity" extension?
The text was updated successfully, but these errors were encountered: