-
Notifications
You must be signed in to change notification settings - Fork 356
Default values don't get applied to objects inside of an array #417
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
@pcjacobse Thanks for reporting this. I've found the root cause - the logic that prevents recursive application of defaults is being incorrectly triggered for arrays, with the result that the library thinks it has already applied the default value for Currently thinking of the best way to address this. |
@mathroc Do you have an opinion? The problem is the call to Obviously this needs fixing, but it may require changing the recursion logic for defaults. |
@erayd sorry I missed this, I’ll take a look at this in the next few days |
@erayd this seems a bit tricky 😕 one think though, shouldn't it will still cause problems when default items are defined inside arrays but that's not the case in @pcjacobse exemple |
@mathroc @erayd @pcjacobse |
@krismckay Line 273 of UndefinedConstraint.php (branch 6.0.0-dev) is Overall, I like the fundamental approach of your idea. The implementation as you've posted it isn't quite suitable (the path passed for recursion needs to be correct) - however, recursing within this block is a good idea, and seems like an ideal solution to the problem. If you are intending to submit a PR for this, please base it on 6.0.0-dev, and address the issues above. If not, let me know, and I'll do a PR when I have the time. |
False alarm! .. Digging into this a little more I found it is all working fine, the issue was in my formatting of the schema. Rather then making the array definition an object, I had it as an array of objects which was causing the validation to miss the array items. To illustrate, I had this (which breaks):
When I should have had this:
|
Closing as reported to be a false alarm. |
Hi,
It seems that the default values don't get applied to objects inside of an array.
It looks like that only the top level object gets their default values applied.
The validation in the sub-object does work (like type checking and required fields).
I'm running version 5.2.0
Example:
I expect the 'test' property to be filled with the default value if not present.
Gives:
The text was updated successfully, but these errors were encountered: