diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4d50e6a..12cec7c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -149,6 +149,8 @@ jobs: - name: 'Upload to Codecov' uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: files: ./coverage.xml fail_ci_if_error: true diff --git a/Serializer/Normalizer/ConstraintViolationListNormalizer.php b/Serializer/Normalizer/ConstraintViolationListNormalizer.php index f67583a..dd0072b 100644 --- a/Serializer/Normalizer/ConstraintViolationListNormalizer.php +++ b/Serializer/Normalizer/ConstraintViolationListNormalizer.php @@ -63,6 +63,8 @@ public function normalize(mixed $object, string $format = null, array $context = { $result = $this->symfonyConstraintViolationListNormalizer->normalize($object, $format, $context); + $this->removeInternalViolationFields($result); + if (\is_array($result) && \array_key_exists('detail', $result) && $result['detail']) { $messages = explode("\n", $result['detail']); @@ -79,4 +81,18 @@ public function normalize(mixed $object, string $format = null, array $context = return $result; } + + /** + * @param array $data + */ + private function removeInternalViolationFields(array &$data): void + { + if (isset($data['violations'])) { + foreach ($data['violations'] as &$violation) { + unset($violation['template'], $violation['parameters']); + $this->removeInternalViolationFields($violation); + } + unset($violation); + } + } } diff --git a/Tests/Serializer/Normalizer/ConstraintViolationListNormalizerTest.php b/Tests/Serializer/Normalizer/ConstraintViolationListNormalizerTest.php index 1c79fc5..f34c77c 100644 --- a/Tests/Serializer/Normalizer/ConstraintViolationListNormalizerTest.php +++ b/Tests/Serializer/Normalizer/ConstraintViolationListNormalizerTest.php @@ -49,13 +49,32 @@ public function testNormalize(string $originDetail, string $resultDetail): void ->expects(self::once()) ->method('normalize') ->with($object, $format, $context) - ->willReturn(['detail' => $originDetail]) + ->willReturn([ + 'detail' => $originDetail, + 'violations' => [ + [ + 'propertyPath' => 'test', + 'title' => 'test', + 'type' => 'test', + 'template' => 'test', + 'parameters' => 'test', + ] + ] + ]) ; $result = (array) $this->normalizer->normalize($object, $format, $context); self::assertArrayHasKey('detail', $result); self::assertSame($resultDetail, $result['detail']); + self::assertSame( + [ + 'propertyPath' => 'test', + 'title' => 'test', + 'type' => 'test', + ], + $result['violations'][0], + ); } public static function dataProviderForTestNormalize(): iterable