diff --git a/src/JsonSchema/Constraints/NumberConstraint.php b/src/JsonSchema/Constraints/NumberConstraint.php index 5a809774..108fd245 100644 --- a/src/JsonSchema/Constraints/NumberConstraint.php +++ b/src/JsonSchema/Constraints/NumberConstraint.php @@ -64,6 +64,11 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $i = $this->addError($path, 'Must be a multiple of ' . $schema->multipleOf, 'multipleOf', array('multipleOf' => $schema->multipleOf)); } + // Verify enum + if (isset($schema->enum)) { + $this->checkEnum($element, $schema, $path, $i); + } + $this->checkFormat($element, $schema, $path, $i); } diff --git a/src/JsonSchema/Constraints/StringConstraint.php b/src/JsonSchema/Constraints/StringConstraint.php index c66af1ed..b5d519d7 100644 --- a/src/JsonSchema/Constraints/StringConstraint.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -45,6 +45,11 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $i = )); } + // Verify enum + if (isset($schema->enum)) { + $this->checkEnum($element, $schema, $path, $i); + } + $this->checkFormat($element, $schema, $path, $i); } diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index dac14358..61984a38 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -71,6 +71,21 @@ public function getInvalidTests() } } }' + ), + array( + '{"data": ["a", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' ) ); } @@ -168,6 +183,21 @@ public function getValidTests() } } }' + ), + array( + '{"data": ["c", "c", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' ) ); }