-
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
Does array include allow nested object properties #553
Comments
I've copy/pasted your sample without any modification and I can't reproduce the bug. |
Hmm...I'm flummoxed. I edited the sample a couple minutes after posting as I forgot the important bit: Joi.array().includes(Joi.object(objectSchema)) This works for you? If so...feel free to close. I'll re-open if I can't get this working after digging in a bit further. |
Taking that exact code you run into this error ? Maybe you fixed it while writing the issue. |
Ah ha....I'm good now... I may I've run into this: #495 My schema was slightly more complicated than my example. Joi wasn't telling which deeply nested property was not validating...it reported at the parent object level. See above example...I had an issue with prop3.nestprop2, for example, but the error was: 'value at position 0 fails because prop3 is not allowed'. prop3 was in the error, not prop3.nestprop2. Feel free to close. |
Can you test your case against the master branch since I did not have any confirmation that my fix worked ? |
Is this correct?
or
sorry for ignorance. I tried both above. Unfortunately I did not get an error specified at the nested object property. I can see that the error has changed slightly however, so I believe I'm on master... value at position 0 fails because ["prop3" is not allowed] Note the brackets around the error. |
This is probably the master yes, can you provide the code you run to get that error ? |
Done... Seems still issue in master...simply make a typo in the Schema... see in the objectSchema I have a typo...prop3.nestprop3 but in my array[0].prop3.nestpro2. (nestprop3 vs nestprop2 is the typo)
You get: [ValidationError: "value" at position 0 fails because ["nestprop3" is required]] |
OK, I've changed that part so it now gives |
I think that covers my case, where I couldn't see the prop failing, as well as 495 too. I'm good with that! |
Thank you! |
Hello...
I'm having a difficult time trying to validate an array which includes an object of nested properties. Should this work?
I've looked through the Joi tests for this case where Jo.array().includes(nested object), but can not see an example there.
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L93
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L109
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L301
None of the tests seem to test a nested object included in an array ... so perhaps this should not work?
Strangely Joi is reporting 'prop3' is not allowed, when in the schema it's defined as required.
Thank you
-M
The text was updated successfully, but these errors were encountered: