-
Notifications
You must be signed in to change notification settings - Fork 357
Array properties with array items listed in enums does not validate properly #549
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
Conversation
@erayd There is two more ways to fix issue:
If any of above ideas are correct, just approve me and I will update PR. |
@justinrainbow @erayd Is there any chance that PR will be applied? Could you please add some reaction for that? |
@malinink I missed this PR sorry - will code review this weekend. Once that's done, @bighappyface will need to merge it. @justinrainbow is no longer involved with this project, and hasn't been for years, even though it's hosted on his GitHub account. |
@bighappyface, @erayd, Any chance of this getting approved and merged soon? We have several occurrences now where this problem is impacting our validation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following change works as an alternative approach to the changes to NumberConstraint
and StringConstraint
as the alternative approach suggested by @erayd in the pull-request comments:
diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php
index 49841a4..b8200f7 100644
--- a/src/JsonSchema/Constraints/CollectionConstraint.php
+++ b/src/JsonSchema/Constraints/CollectionConstraint.php
@@ -84,6 +84,9 @@ class CollectionConstraint extends Constraint
$typeValidator->check($v, $schema->items, $k_path, $i);
$validator->check($v, $schema->items, $k_path, $i);
+ if (isset($schema->items->enum)) {
+ $this->checkEnum($v, $schema->items, $k_path, $i);
+ }
}
unset($v); /* remove dangling reference to prevent any future bugs
* caused by accidentally using $v elsewhere */
I've also run into this issue, with: "broadcast_level": {
"type": "array",
"items": {
"type": "string",
"enum": [
"now",
"order"
]
},
"minItems": 1
}, Always validates with an invalid enum value. However, if I change the type |
@rbchasesc I'm not happy with this PR as currently written (because it calls general validation from a type-specific area, and has redundant code - both of which are things which I've been trying to clean out of this library for a while). I'm looking at this now and will propose an alternative shortly - stand by. |
@rbchasesc Could you please confirm whether you are seeing this bug in 6.0.0 (the current master branch)? I've applied your test cases to it, and they seem to pass correctly, indicating that this bug is probably already fixed and we just need to backport something. As a general rule, new PRs should not be opened against the 5.x.x branch. Bugfixes are sometimes an exception - depending on whether it's a fix that's also relevant to master, or if it's exclusively a 5.x.x bug. |
@rbchasesc Upon further investigation, I think this whole issue is being caused by the optimisation block, which I eliminated in 6.0.0 in order to resolve a number of other bugs. However, I didn't backport that to 5.x.x for some reason - |
@erayd I only tested this as a fix to the 5.2.7 tag as we are currently using that version as our "stable" deployed version of this library. We haven't utilize 6.0.0-dev or master as there is no officially tagged 6.0.0 release....yet 😄 . Standing by for what ever comes out of your backport effort. |
@rbchasesc Fair call :-). 6.0.0 is missing enough stuff (mainly documentation and a couple of significant bugfixes) that it's not properly ready to release, but it should be fairly stable, and does have a number of advantages that may make it preferable to 5.x.x in some cases. However, I'll continue to backport stuff into 5.x.x until we have an actual release, so if you'd rather stick with that, go for it 👍. I've backported the relevant changes to 5.2.8 for you - just waiting on @bighappyface to merge it. Could you please create a new PR (or change this one) against the master branch, which includes the test cases from this PR? The tests as you have them are fine, although a couple of brief comments would be useful to clarify what is being tested. The logic changes in this PR are unnecessary, and can be discarded. |
@erayd Awesome news on getting this into 5.2.8! Will keep an eye out for the merge and the new tagged release version. I'll see if I can get to the tests PR tomorrow as it's getting later over here. Thanks again for jumping on this one. |
@erayd Per your request last week, went with a new PR #559 that has several test cases and is targeting Huge thanks to you and @bighappyface for getting that backport done, merged and v5.2.8 released. |
@rbchasesc Awesome - thanks for that 👍. |
Approve example
close #547