Skip to content

Commit 1645ef8

Browse files
committed
fix: stop AdditionalPropertiesKeyword from throwing incorrect errors #148
1 parent 7128277 commit 1645ef8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Keywords/AdditionalPropertiesKeyword.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio
5050
return null;
5151
}
5252

53-
$props = $context->getUncheckedProperties();
53+
$props = array_diff(
54+
$context->getUncheckedProperties(),
55+
$this->getSchemaProperties($schema)
56+
);
5457

5558
if (!$props) {
5659
return null;
@@ -80,4 +83,18 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio
8083

8184
return $error;
8285
}
83-
}
86+
87+
/**
88+
* Get the names of the properties defined in the schema.
89+
*/
90+
protected function getSchemaProperties(Schema $schema): array
91+
{
92+
$data = $schema->info()->data();
93+
94+
if (!is_object($data) || !isset($data->properties)) {
95+
return [];
96+
}
97+
98+
return array_keys(get_object_vars($data->properties));
99+
}
100+
}

0 commit comments

Comments
 (0)