diff --git a/src/Schema/Keywords/Nullable.php b/src/Schema/Keywords/Nullable.php index 9569ac27..58dea829 100644 --- a/src/Schema/Keywords/Nullable.php +++ b/src/Schema/Keywords/Nullable.php @@ -27,6 +27,10 @@ public function validate($data, bool $nullable): void public function nullableByType(): bool { - return ! is_string($this->parentSchema->type) && in_array('null', $this->parentSchema->type); + if (is_string($this->parentSchema->type)) { + return $this->parentSchema->type === 'null'; + } + + return in_array('null', $this->parentSchema->type); } } diff --git a/tests/Schema/Keywords/NullableTest.php b/tests/Schema/Keywords/NullableTest.php index db9c8638..61c649cb 100644 --- a/tests/Schema/Keywords/NullableTest.php +++ b/tests/Schema/Keywords/NullableTest.php @@ -25,6 +25,20 @@ public function testItValidatesNullableGreen(): void $this->addToAssertionCount(1); } + public function testItValidatesNullableStandaloneGreen(): void + { + $spec = <<loadRawSchema($spec); + $data = null; + + (new SchemaValidator())->validate($data, $schema); + $this->addToAssertionCount(1); + } + public function testItValidatesNullableRed(): void { $spec = <<