diff --git a/src/Schema/Keywords/Nullable.php b/src/Schema/Keywords/Nullable.php index 9569ac27..68c4350f 100644 --- a/src/Schema/Keywords/Nullable.php +++ b/src/Schema/Keywords/Nullable.php @@ -7,7 +7,7 @@ use League\OpenAPIValidation\Schema\Exception\KeywordMismatch; use function in_array; -use function is_string; +use function is_array; class Nullable extends BaseKeyword { @@ -27,6 +27,6 @@ public function validate($data, bool $nullable): void public function nullableByType(): bool { - return ! is_string($this->parentSchema->type) && in_array('null', $this->parentSchema->type); + return is_array($this->parentSchema->type) && in_array('null', $this->parentSchema->type); } } diff --git a/tests/FromCommunity/IssueNullablePropertyTest.php b/tests/FromCommunity/IssueNullablePropertyTest.php new file mode 100644 index 00000000..3086e36c --- /dev/null +++ b/tests/FromCommunity/IssueNullablePropertyTest.php @@ -0,0 +1,80 @@ +fromJson($json) + ->getRequestValidator(); + + $request = new Request( + 'POST', + 'headers:/api/data', + ['Content-Type' => 'application/json'], + json_encode(['value' => null]) + ); + + $this->expectException(InvalidBody::class); + + $requestValidator->validate($request); + } +}