Skip to content

Commit

Permalink
Merge pull request #4 from AppsDevTeam/json-schema-improvements
Browse files Browse the repository at this point in the history
Add support for 'contains' on array type
  • Loading branch information
thorewi authored Jan 10, 2022
2 parents 04bfc6a + 5231dd3 commit 4d86398
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ApiRouteFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,22 @@ protected function verifyBodyFormat($body, $schema, $propertyPath = 'body') {
}
// Check elements of an array
else if ($type === 'array') {
$matches = 0;
foreach ($body as $key => $value) {
if (isset($schema['items'])) {
$this->verifyBodyFormat($value, $schema['items'], "{$propertyPath}[{$key}]");
}
if (isset($schema['contains'])) {
try {
$this->verifyBodyFormat($value, $schema['contains'], "{$propertyPath}[{$key}]");
$matches++;
} catch (FormatInputError $e) {
// Not all need to match this
}
}
}
if (isset($schema['contains']) && $matches === 0) {
throw new FormatInputError("At least one element must meet 'contains' subschema @$propertyPath");
}
}
// Must not meet "not" subschema
Expand Down

0 comments on commit 4d86398

Please sign in to comment.