From 895127f04be23df93a67c73d33c115246b701b68 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 19 Jul 2023 10:29:21 -0700 Subject: [PATCH 1/3] Added 'detail' in validation error response --- README.md | 6 ++---- src/Model/ErrorWithViolation.php | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) 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..19dd442 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($violation->getMessage()); $model->setSource([ 'parameter' => $violation->getPropertyPath(), + // @deprecated The 'message' will be removed in a future version 'message' => $violation->getMessage(), ]); From 66020a3ed848ac8cecdc9a8e2df9b42d4a0dfe47 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 19 Jul 2023 10:39:09 -0700 Subject: [PATCH 2/3] Fixed CI --- tests/Unit/Model/ErrorWithViolationTest.php | 1 + 1 file changed, 1 insertion(+) 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', From 67169adaa93e88dc9cef24fbb1e756e2c57a999d Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 19 Jul 2023 10:41:10 -0700 Subject: [PATCH 3/3] static fixes --- src/Model/ErrorWithViolation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/ErrorWithViolation.php b/src/Model/ErrorWithViolation.php index 19dd442..ba3b0c6 100644 --- a/src/Model/ErrorWithViolation.php +++ b/src/Model/ErrorWithViolation.php @@ -17,7 +17,7 @@ class ErrorWithViolation extends AbstractError public static function create(ConstraintViolationInterface $violation, string $title = 'Validation failed') { $model = new static($title, 400); - $model->setDescription($violation->getMessage()); + $model->setDescription((string) $violation->getMessage()); $model->setSource([ 'parameter' => $violation->getPropertyPath(), // @deprecated The 'message' will be removed in a future version