diff --git a/src/Keywords/AdditionalPropertiesKeyword.php b/src/Keywords/AdditionalPropertiesKeyword.php index b3ac59f..a3530c6 100644 --- a/src/Keywords/AdditionalPropertiesKeyword.php +++ b/src/Keywords/AdditionalPropertiesKeyword.php @@ -50,7 +50,10 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio return null; } - $props = $context->getUncheckedProperties(); + $props = array_diff( + $context->getUncheckedProperties(), + $this->getSchemaProperties($schema) + ); if (!$props) { return null; @@ -80,4 +83,18 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio return $error; } -} \ No newline at end of file + + /** + * Get the names of the properties defined in the schema. + */ + protected function getSchemaProperties(Schema $schema): array + { + $data = $schema->info()->data(); + + if (!is_object($data) || !isset($data->properties)) { + return []; + } + + return array_keys(get_object_vars($data->properties)); + } +}