diff --git a/src/Schema/Keywords/Type.php b/src/Schema/Keywords/Type.php index ea24f345..6b730d34 100644 --- a/src/Schema/Keywords/Type.php +++ b/src/Schema/Keywords/Type.php @@ -42,7 +42,7 @@ public function validate($data, string $type, ?string $format = null) : void { switch ($type) { case CebeType::OBJECT: - if (! is_object($data) && ! (is_array($data) && ArrayHelper::isAssoc($data))) { + if (! is_object($data) && ! (is_array($data) && ArrayHelper::isAssoc($data)) && $data !== []) { throw TypeMismatch::becauseTypeDoesNotMatch(CebeType::OBJECT, $data); } break; diff --git a/tests/FromCommunity/EmptyObjectValidationTest.php b/tests/FromCommunity/EmptyObjectValidationTest.php new file mode 100644 index 00000000..5b2e0430 --- /dev/null +++ b/tests/FromCommunity/EmptyObjectValidationTest.php @@ -0,0 +1,48 @@ +fromYaml($yaml)->getServerRequestValidator(); + + $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) + ->withHeader('Content-Type', 'application/json') + ->withBody(stream_for('{}')); + + $validator->validate($psrRequest); + + $this->addToAssertionCount(1); + } +}