Skip to content

Commit

Permalink
feature #29130 [Serializer] Normalize constraint violation parameters…
Browse files Browse the repository at this point in the history
… (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
  • Loading branch information
fabpot committed Mar 17, 2019
2 parents 6fa4d2b + 32c90eb commit b443176
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.3.0
-----

* added the list of constraint violations' parameters in `ConstraintViolationListNormalizer`

4.2.0
-----

Expand Down
Expand Up @@ -49,6 +49,7 @@ public function normalize($object, $format = null, array $context = [])
$violationEntry = [
'propertyPath' => $propertyPath,
'title' => $violation->getMessage(),
'parameters' => $violation->getParameters(),
];
if (null !== $code = $violation->getCode()) {
$violationEntry['type'] = sprintf('urn:uuid:%s', $code);
Expand Down
Expand Up @@ -38,7 +38,7 @@ public function testSupportsNormalization()
public function testNormalize()
{
$list = new ConstraintViolationList([
new ConstraintViolation('a', 'b', [], 'c', 'd', 'e', null, 'f'),
new ConstraintViolation('a', 'b', ['value' => 'foo'], 'c', 'd', 'e', null, 'f'),
new ConstraintViolation('1', '2', [], '3', '4', '5', null, '6'),
]);

Expand All @@ -52,11 +52,15 @@ public function testNormalize()
'propertyPath' => 'd',
'title' => 'a',
'type' => 'urn:uuid:f',
'parameters' => [
'value' => 'foo',
],
],
[
'propertyPath' => '4',
'title' => '1',
'type' => 'urn:uuid:6',
'parameters' => [],
],
],
];
Expand Down

0 comments on commit b443176

Please sign in to comment.