Skip to content

Commit e8a72f0

Browse files
committed
dont validate draft4 required attribute when value is undefined
- fixes regression introduced by 61059b2
1 parent 3140166 commit e8a72f0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/JsonSchema/Constraints/Undefined.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ protected function validateCommonProperties($value, $schema = null, $path = null
117117

118118
// Verify required values
119119
if (is_object($value)) {
120-
if (isset($schema->required) && is_array($schema->required) ) {
120+
121+
if (!($value instanceof Undefined) && isset($schema->required) && is_array($schema->required) ) {
121122
// Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
122123
foreach ($schema->required as $required) {
123124
if (!property_exists($value, $required)) {
124125
$this->addError($path, "the property " . $required . " is required");
125126
}
126127
}
127-
} else if (isset($schema->required)) {
128+
} else if (isset($schema->required) && !is_array($schema->required)) {
128129
// Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
129130
if ( $schema->required && $value instanceof Undefined) {
130131
$this->addError($path, "is missing and it is required");

0 commit comments

Comments
 (0)