Skip to content

Commit 3ec2db5

Browse files
committed
Merge pull request #47 from mchiocca/master
Fix #46. Add support for draft v4 minProperties and maxProperties.
2 parents 3e40eaa + 522f0ae commit 3ec2db5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/JsonSchema/Constraints/Undefined.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ protected function validateCommonProperties($value, $schema = null, $path = null
139139
}
140140
}
141141

142+
// Verify minimum and maximum number of properties
143+
if (is_object($value)) {
144+
if (isset($schema->minProperties)) {
145+
if (count(get_object_vars($value)) < $schema->minProperties) {
146+
$this->addError($path, "must contain a minimum of " + $schema->minProperties + " properties");
147+
}
148+
}
149+
if (isset($schema->maxProperties)) {
150+
if (count(get_object_vars($value)) > $schema->maxProperties) {
151+
$this->addError($path, "must contain no more than " + $schema->maxProperties + " properties");
152+
}
153+
}
154+
}
155+
142156
// Verify that dependencies are met
143157
if (is_object($value) && isset($schema->dependencies)) {
144158
$this->validateDependencies($value, $schema->dependencies, $path);

tests/JsonSchema/Tests/Drafts/Draft4Test.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ protected function getSkippedTests()
1919
'allOf.json',
2020
'anyOf.json',
2121
'definitions.json',
22-
'maxProperties.json',
23-
'minProperties.json',
2422
'multipleOf.json',
2523
'not.json',
2624
'oneOf.json',

0 commit comments

Comments
 (0)