diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index c0337200..5f9d6bc8 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -166,7 +166,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null } // Verify minimum and maximum number of properties - if (is_object($value)) { + if (is_object($value) && !($value instanceof UndefinedConstraint)) { if (isset($schema->minProperties)) { if (count(get_object_vars($value)) < $schema->minProperties) { $this->addError($path, "Must contain a minimum of " . $schema->minProperties . " properties", 'minProperties', array('minProperties' => $schema->minProperties,)); diff --git a/tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php b/tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php index 1b477845..d40f6701 100644 --- a/tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php +++ b/tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php @@ -63,6 +63,98 @@ public function getValidTests() "value":{"type":"array","minItems":2,"maxItems":4} } }' + ), + // Regression test for issue 215 + array( + '{ + "campaign": 1, + "offset": 0, + "service_provider": 3, + "include_hotel": false, + "arrival": "2016-01-20", + "departure": "2016-01-27", + "session": "foobar", + "ip": "127.0.0.1", + "language_iso_code": "de", + "travellers": [ + 18, + 18, + 18 + ] + }', + '{ + "type": "object", + "additionalProperties": false, + "required": [ + "session", + "include_hotel", + "arrival", + "departure", + "ip", + "travellers", + "language_iso_code" + ], + "properties": { + "session": { + "type": "string" + }, + "campaign": { + "type": "integer" + }, + "service_provider": { + "type": "integer" + }, + "include_hotel": { + "type": "boolean" + }, + "arrival": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" + }, + "departure": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" + }, + "ip": { + "type": "string" + }, + "offerId": { + "type": "integer", + "minimum": 1 + }, + "quiet": { + "type": "boolean" + }, + "language_iso_code": { + "type": "string" + }, + "travellers": { + "type": "array", + "minItems": 1, + "maxItems": 16, + "items": { + "type": "integer" + } + }, + "rooms": { + "type": "object", + "additionalProperties": false, + "minProperties": 1, + "maxProperties": 2, + "properties": { + "size_1": { + "type": "number" + }, + "size_2": { + "type": "number" + } + } + }, + "offset": { + "type": "integer" + } + } + }' ) ); }