Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
$propertyName = end($propertyPaths);
$this->addError(ConstraintError::REQUIRED(), $path, array('property' => $propertyName));
}
} else {
// if the value is both undefined and not required, skip remaining checks
// in this method which assume an actual, defined instance when validating.
if ($value instanceof self) {
return;
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/Constraints/NotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public function getInvalidTests()
}
}
}'
),
array( // check that a missing, required property is correctly validated
'{"y": "foo"}',
'{
"type": "object",
"required": ["x"],
"properties": {
"x": {
"not": {
"type": "null"
}
}
}
}'
)
);
}
Expand Down Expand Up @@ -69,6 +83,19 @@ public function getValidTests()
}
}
}'
),
array( // check that a missing, non-required property isn't validated
'{"y": "foo"}',
'{
"type": "object",
"properties": {
"x": {
"not": {
"type": "null"
}
}
}
}'
)
);
}
Expand Down