-
Notifications
You must be signed in to change notification settings - Fork 1.5k
array().single() #498
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
Comments
Still not convinced about the usefulness of such construct, it seems like a poorly designed frontend, am I missing something here ? If you intend to pass an array just do it, and the accepted pattern for it is to put |
Forget about front end. I have these rules in the hapi schema for every field that accepts a value or array of values. I really don't care about the query string use case, but this does address it. |
Fair point. |
Renamed it to |
It's both, like |
|
How is that different? |
There's no possible failure to expect from |
There could: the single item provided does not match the allowed array items. |
This is then referring to the |
I think the error would be more useful if it referred to the single item state. Does the current solution address an array of arrays? |
The current solution wraps into an array if it's not, and there's probably no way to know about an array of arrays in one pass. |
I think that's part of the problem in this debate. |
This kind of concern was not part of the original issue. |
Might be worth to reconsider fixing or removing for now. The way it should work is by checking if the value matches the plain rule (the array rules) and if not, check if it would pass as a single array item, and if yes, then convert to an array if convert is on. I have not looked into how to implement it. |
There are only so many days to hapi 8, that'll probably be the last one to land. |
Your call. |
The "array of arrays" is dealt with, not so sure about the error message though, it's a lot of added complexity just to change from "position 0 does not match..." to "your single item doesn not match...". The language doesn't seem to support composability of errors yet so... |
Don't know. When we didn't do this correctly in the past (many times) it always came back to bite us in the ass. |
I'm wondering about the message to show in the case of array of arrays, should it be something like "the single item doesn't match..." or "value at position 0 doesn't match...", in essence, should it be the 1st pass error or the 2nd one ? |
Ideally the first pass, but not worth complexity over. |
Should be good to go now. |
Was the name changed back to |
Yes. |
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. |
A different take on #474
Allows an array value to pass if the value would be a valid array element. It conversion is enabled, turns the item into an array.
Joi.array().includes(Joi.number()).single()
will match[1]
and1
and will result in[1]
in both cases.The text was updated successfully, but these errors were encountered: