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
Handle sequentially validator constraints when generating property metadata #4139
Handle sequentially validator constraints when generating property metadata #4139
Conversation
73a91ad
to
dea8150
Compare
src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php
Show resolved
Hide resolved
Hello,
|
dea8150
to
b9d7812
Compare
For example there is an |
I see. It seems OK to me to use all the nested constraints of Shouldn't it be recursive instead of a loop? It seems to me that you can combine the composite constraints. |
So you mean I should do recursive constraint resolving? :) |
Yes, does it seem correct to you? |
Maybe.. added a second commit with flattening |
|
||
foreach ($propertyConstraints as $propertyConstraint) { | ||
if ($propertyConstraint instanceof AtLeastOneOf) { | ||
continue; |
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.
Why continuing in this case? I think we should take the constraints of AtLeastOneOf
too for the property metadata, don't you think?
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.
Hmm.. Not sure for real, because:
@Assert\AtLeastOneOf({
@Assert\Length(min=1, max=2),
@Assert\Length(min=5, max=6)
})
The last one would override the first one and then the schema would be wrong 🤔
Also with the flattening I think this could go wrong, because the restrictions would be directly applied to the property, not to the array values
|
You're right, I think we should blacklist (or maybe it would be preferable to whitelist the wanted constraints) |
Maybe for now would be good to handle the |
Yes, please do, sorry for the unwanted change. |
b834eb7
to
6fb68e1
Compare
All good :) I agree, one problem at a time :) |
6fb68e1
to
f2c84af
Compare
tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
f2c84af
to
0564555
Compare
I'm checking if we shouldn't merge this PR as a bugfix. |
@soyuka said to submit as a feature 🙂 |
While this looks like an enhancement (as it's adding support for a Symfony feature that is currently not supported), I think it qualifies as a bugfix as it is actually fixing compatibility with Symfony 5.1 (at least one way to use Symfony 5.1). |
0564555
to
cae1758
Compare
Thanks @norkunas ! |
Thanks for merging :) |
Currently property metadata from validator constraints (length/regex etc.) is only taken when these constraints are applied directly. Since Symfony 5.1 there is Sequentially constraint which allows to validate as a group sequence but much easier. But api platform doesn't take them because they're nested inside the Sequentially constraint.
I have updated to include all nested constraints from the Composite, but maybe that's too wide?Also not sure about that maybe constraint flattening should be recursive?