From 84decc9a666dccef5e7d8241622898a2023368bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Chrobak?= Date: Fri, 29 Apr 2016 17:04:39 +0200 Subject: [PATCH] Skips min/max properties validation for non objects --- .../Constraints/ObjectConstraint.php | 9 +- .../Constraints/MinMaxPropertiesTest.php | 108 ++++++++++++++++++ 2 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 tests/JsonSchema/Tests/Constraints/MinMaxPropertiesTest.php diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index 0cfb59a3..f40e1202 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -81,12 +81,8 @@ public function validateElement($element, $matches, $objectDefinition = null, $p { $this->validateMinMaxConstraint($element, $objectDefinition, $path); foreach ($element as $i => $value) { - - $property = $this->getProperty($element, $i, new UndefinedConstraint()); $definition = $this->getProperty($objectDefinition, $i); - $this->validateMinMaxConstraint(!($property instanceof UndefinedConstraint) ? $property : $element, $definition, $path); - // no additional properties allowed if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) { $this->addError($path, "The property " . $i . " is not defined and the definition does not allow additional properties", 'additionalProp'); @@ -111,6 +107,11 @@ public function validateElement($element, $matches, $objectDefinition = null, $p // normal property verification $this->checkUndefined($value, new \stdClass(), $path, $i); } + + $property = $this->getProperty($element, $i, new UndefinedConstraint()); + if (is_object($property)) { + $this->validateMinMaxConstraint(!($property instanceof UndefinedConstraint) ? $property : $element, $definition, $path); + } } } diff --git a/tests/JsonSchema/Tests/Constraints/MinMaxPropertiesTest.php b/tests/JsonSchema/Tests/Constraints/MinMaxPropertiesTest.php new file mode 100644 index 00000000..8c3a641d --- /dev/null +++ b/tests/JsonSchema/Tests/Constraints/MinMaxPropertiesTest.php @@ -0,0 +1,108 @@ +