From 92640227e401460ca7dadb17f2bdf06064adf3de Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 20 Jan 2024 12:23:18 +0900 Subject: [PATCH 1/3] Validation only when body content is present --- src/JsonSchema/Interceptor/JsonSchemaInterceptor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php index ae5000fc..78b4318b 100644 --- a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php +++ b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php @@ -60,7 +60,7 @@ public function invoke(MethodInvocation $invocation): ResourceObject $ro = $invocation->proceed(); assert($ro instanceof ResourceObject); - if ($ro->code === 200 || $ro->code === 201) { + if ($ro->body && $ro->code === 200 || $ro->code === 201) { $this->validateResponse($ro, $jsonSchema); } From 01f6ad7077e0ef7da008693c31e42fc00c372d25 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 20 Jan 2024 17:03:04 +0900 Subject: [PATCH 2/3] fixup! Validation only when body content is present --- src/JsonSchema/Interceptor/JsonSchemaInterceptor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php index 78b4318b..b92d197b 100644 --- a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php +++ b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php @@ -60,7 +60,7 @@ public function invoke(MethodInvocation $invocation): ResourceObject $ro = $invocation->proceed(); assert($ro instanceof ResourceObject); - if ($ro->body && $ro->code === 200 || $ro->code === 201) { + if ($ro->body !== [] && $ro->code === 200 || $ro->code === 201) { $this->validateResponse($ro, $jsonSchema); } From 09fa1101b47fd6ae12dd9f1beaa1ec87af16eda4 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 20 Jan 2024 17:06:36 +0900 Subject: [PATCH 3/3] Fix CS --- src/JsonSchema/Interceptor/JsonSchemaInterceptor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php index b92d197b..7648effa 100644 --- a/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php +++ b/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php @@ -60,7 +60,7 @@ public function invoke(MethodInvocation $invocation): ResourceObject $ro = $invocation->proceed(); assert($ro instanceof ResourceObject); - if ($ro->body !== [] && $ro->code === 200 || $ro->code === 201) { + if ($ro->body !== [] && $ro->code === 200 || $ro->code === 201) { $this->validateResponse($ro, $jsonSchema); }