Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 522fe71

Browse filesBrowse files
committed
Fix last comments
1 parent 6ecb745 commit 522fe71
Copy full SHA for 522fe71

File tree

2 files changed

+14
-8
lines changed
Filter options

2 files changed

+14
-8
lines changed

‎src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,24 @@ public function normalize($object, $format = null, array $context = array())
3232
$violations = array();
3333
$messages = array();
3434
foreach ($object as $violation) {
35-
$violations[] = array(
36-
'propertyPath' => $violation->getPropertyPath(),
37-
'type' => sprintf('urn:uuid:%s', $violation->getCode()),
35+
$propertyPath = $violation->getPropertyPath();
36+
37+
$violationEntry = array(
38+
'propertyPath' => $propertyPath,
3839
'title' => $violation->getMessage(),
3940
);
40-
$propertyPath = $violation->getPropertyPath();
41+
if (null !== $code = $violation->getCode()) {
42+
$violationEntry['type'] = sprintf('urn:uuid:%s', $code);
43+
}
44+
45+
$violations[] = $violationEntry;
46+
4147
$prefix = $propertyPath ? sprintf('%s: ', $propertyPath) : '';
4248
$messages[] = $prefix.$violation->getMessage();
4349
}
4450

4551
$result = array(
46-
'type' => $context['type'] ?? 'https://symfony.com/validation-error',
52+
'type' => $context['type'] ?? 'https://symfony.com/errors/validation',
4753
'title' => $context['title'] ?? 'Validation Failed',
4854
);
4955
if (isset($context['status'])) {

‎src/Symfony/Component/Serializer/Tests/Normalizer/ConstraintViolationListNormalizerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ConstraintViolationListNormalizerTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ public function testNormalize()
4343
));
4444

4545
$expected = array(
46-
'type' => 'https://symfony.com/validation-error',
46+
'type' => 'https://symfony.com/errors/validation',
4747
'title' => 'Validation Failed',
4848
'detail' => 'd: a
4949
4: 1',
5050
'violations' => array(
5151
array(
5252
'propertyPath' => 'd',
53-
'type' => 'urn:uuid:f',
5453
'title' => 'a',
54+
'type' => 'urn:uuid:f',
5555
),
5656
array(
5757
'propertyPath' => '4',
58-
'type' => 'urn:uuid:6',
5958
'title' => '1',
59+
'type' => 'urn:uuid:6',
6060
),
6161
),
6262
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.