diff --git a/composer.json b/composer.json index 3f573380..81e0ebe3 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require": { "php": ">=7.2", "ext-json": "*", - "cebe/php-openapi": "^1.3", + "cebe/php-openapi": "^1.6", "league/uri": "^6.3", "psr/cache": "^1.0 || ^2.0 || ^3.0", "psr/http-message": "^1.0", diff --git a/src/Schema/SchemaValidator.php b/src/Schema/SchemaValidator.php index 55471b44..f1f75937 100644 --- a/src/Schema/SchemaValidator.php +++ b/src/Schema/SchemaValidator.php @@ -57,7 +57,7 @@ public function validate($data, CebeSchema $schema, ?BreadCrumb $breadCrumb = nu try { // These keywords are not part of the JSON Schema at all (new to OAS) - (new Nullable($schema))->validate($data, $schema->nullable); + (new Nullable($schema))->validate($data, $schema->nullable ?? true); // We don't want to validate any more if the value is a valid Null if ($data === null) { diff --git a/tests/FromCommunity/IssueWithNullableMergeTest.php b/tests/FromCommunity/IssueWithNullableMergeTest.php new file mode 100644 index 00000000..9a73f0d5 --- /dev/null +++ b/tests/FromCommunity/IssueWithNullableMergeTest.php @@ -0,0 +1,72 @@ +fromYaml($yaml)->getResponseValidator(); + $operation = new OperationAddress('/api/nullable-merge', 'get'); + + $responseContent = /** @lang JSON */ + ' + { + "result": null + } +'; + + $response = new Response(200, ['Content-Type' => 'application/json'], $responseContent); + + $validator->validate($operation, $response); + + $this->addToAssertionCount(1); + } +} diff --git a/tests/FromCommunity/NullableSchemaTest.php b/tests/FromCommunity/NullableSchemaTest.php new file mode 100644 index 00000000..223b0004 --- /dev/null +++ b/tests/FromCommunity/NullableSchemaTest.php @@ -0,0 +1,62 @@ +fromYaml($yaml)->getResponseValidator(); + $operation = new OperationAddress('/api/nullable', 'get'); + + $responseContent = /** @lang JSON */ + ' +{ + "result": null +} +'; + + $response = new Response(200, ['Content-Type' => 'application/json'], $responseContent); + + $validator->validate($operation, $response); + + $this->addToAssertionCount(1); + } +}