Skip to content

Commit

Permalink
fix: stop AdditionalPropertiesKeyword from throwing incorrect errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BasilLangevin committed Feb 9, 2025
1 parent 7128277 commit 1645ef8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Keywords/AdditionalPropertiesKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,4 +83,18 @@ public function validate(ValidationContext $context, Schema $schema): ?Validatio

return $error;
}
}

/**
* 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));
}
}

0 comments on commit 1645ef8

Please sign in to comment.