[Serializer] Normalize constraint violation parameters#29130
[Serializer] Normalize constraint violation parameters#29130fabpot merged 1 commit intosymfony:masterfrom ogizanagi:constraint_violation_normalizer_parameters
Conversation
|
Note: adding this by default might break CI testing API endpoint responses, but I don't see much more reasons not to do so. So, better keep adding by default, or add a context option for this? |
|
it may be better to make this behaviour opt-in |
|
We don't guarantee that the output of the normalizers will never change. Especially, we don't guarantee that will not add fields. I'm in favor of adding it by default, but only if at least one parameter exists. |
| $violationEntry = array( | ||
| 'propertyPath' => $propertyPath, | ||
| 'title' => $violation->getMessage(), | ||
| 'parameters' => $violation->getParameters(), |
There was a problem hiding this comment.
We should only add this key if at least one parameter exists:
if ($parameters = $violation->getParameters()) {
$violationEntry['parameters'] = $parameters;
}There was a problem hiding this comment.
May I ask what is the motivation behind this?
From my experience, this would just introduce additional complexity/confusion on the client side in the way would be consumed the data structure, only to save a few bytes.
dunglas
left a comment
There was a problem hiding this comment.
Let's merge it as is. Can you rebase please?
|
Now rebased :) |
|
this one is OK too. let's merge it. /cc @dunglas (easy pick) |
|
Thank you @ogizanagi. |
… (ogizanagi) This PR was merged into the 4.3-dev branch. Discussion ---------- [Serializer] Normalize constraint violation parameters | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A? Adding violation constraints' parameters to the normalized data, as these are valuable for an API client. I used `parameters` for now, as it's the name used in `ConstraintViolationInterface::getParameters()`, but what about `placeholders` or `context`? Commits ------- 32c90eb [Serializer] Normalize constraint violation parameters
…eters (ogizanagi) This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Add compared value path to violation parameters | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A While it's not really useful to use as a placeholder in the violation message template (compared to hard-coding it into the message. Nor it is really user-friendly), it becomes handy in conjunction with #29130 for any mapping logic on client-side. Commits ------- 2da226a [Validator] Add compared value path to violation parameters
Adding violation constraints' parameters to the normalized data, as these are valuable for an API client.
I used
parametersfor now, as it's the name used inConstraintViolationInterface::getParameters(), but what aboutplaceholdersorcontext?