diff --git a/README.md b/README.md index 061ada1..b6dfe83 100644 --- a/README.md +++ b/README.md @@ -141,10 +141,9 @@ Example response for validation failed: { "status": "400", "title": "Validation failed", - "detail": "Request parameter is missing or not valid.", + "detail": "This value should not be blank.", "source": { "parameter": "foo", - "message": "This value should not be blank." }, "links": { "about": "http://docs.docs/errors/missing-parameter" @@ -153,10 +152,9 @@ Example response for validation failed: { "status": "400", "title": "Validation failed", - "detail": "Request parameter is missing or not valid.", + "detail": "This value has to be larger than 30.", "source": { "parameter": "bar", - "message": "This value has to be larger than 30." }, "links": { "about": "http://docs.docs/errors/range" diff --git a/src/Model/ErrorWithViolation.php b/src/Model/ErrorWithViolation.php index 642d516..ba3b0c6 100644 --- a/src/Model/ErrorWithViolation.php +++ b/src/Model/ErrorWithViolation.php @@ -17,8 +17,10 @@ class ErrorWithViolation extends AbstractError public static function create(ConstraintViolationInterface $violation, string $title = 'Validation failed') { $model = new static($title, 400); + $model->setDescription((string) $violation->getMessage()); $model->setSource([ 'parameter' => $violation->getPropertyPath(), + // @deprecated The 'message' will be removed in a future version 'message' => $violation->getMessage(), ]); diff --git a/tests/Unit/Model/ErrorWithViolationTest.php b/tests/Unit/Model/ErrorWithViolationTest.php index b156496..11431fd 100644 --- a/tests/Unit/Model/ErrorWithViolationTest.php +++ b/tests/Unit/Model/ErrorWithViolationTest.php @@ -28,6 +28,7 @@ public function testCreate(): void [ 'status' => '400', 'title' => 'someTitle', + 'detail' => 'someMessage', 'source' => [ 'parameter' => 'someProperty', 'message' => 'someMessage',