From c1335f4de1fc063299eff73942931cd751d755fd Mon Sep 17 00:00:00 2001 From: Josh Waihi Date: Mon, 30 Jan 2023 07:56:51 +1300 Subject: [PATCH 1/2] Ensure additionalProperty uses correct schema. --- src/Schema/Keywords/Properties.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/Keywords/Properties.php b/src/Schema/Keywords/Properties.php index 52ae621a..4fc8f0a5 100644 --- a/src/Schema/Keywords/Properties.php +++ b/src/Schema/Keywords/Properties.php @@ -108,7 +108,7 @@ public function validate($data, array $properties, $additionalProperties): void // if not covered by "properties" $schemaValidator->validate( $data[$propName], - $additionalProperties, + $additionalProperties->properties[$propName], $this->dataBreadCrumb->addCrumb($propName) ); } From ebd94eaf80df55615f180b1965cb125b341fdf1d Mon Sep 17 00:00:00 2001 From: Josh Waihi Date: Mon, 30 Jan 2023 08:15:13 +1300 Subject: [PATCH 2/2] Fixed unit tests and added case for additionalProperties of type object. --- src/Schema/Keywords/Properties.php | 2 +- tests/Schema/Keywords/PropertiesTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Schema/Keywords/Properties.php b/src/Schema/Keywords/Properties.php index 4fc8f0a5..f250581f 100644 --- a/src/Schema/Keywords/Properties.php +++ b/src/Schema/Keywords/Properties.php @@ -108,7 +108,7 @@ public function validate($data, array $properties, $additionalProperties): void // if not covered by "properties" $schemaValidator->validate( $data[$propName], - $additionalProperties->properties[$propName], + $additionalProperties->properties[$propName] ?? $additionalProperties, $this->dataBreadCrumb->addCrumb($propName) ); } diff --git a/tests/Schema/Keywords/PropertiesTest.php b/tests/Schema/Keywords/PropertiesTest.php index 82a146e4..158f4926 100644 --- a/tests/Schema/Keywords/PropertiesTest.php +++ b/tests/Schema/Keywords/PropertiesTest.php @@ -120,4 +120,23 @@ public function testItInfersObjectTypeGreen(): void $this->expectException(KeywordMismatch::class); (new SchemaValidator())->validate($data, $schema); } + + public function testItValidatesAdditionalPropertiesBlue(): void + { + $spec = <<loadRawSchema($spec); + $data = ['flag' => true]; + + (new SchemaValidator())->validate($data, $schema); + $this->addToAssertionCount(1); + } }