From e0cb400de67eceb8923e1eeccdf21d507f93c0d4 Mon Sep 17 00:00:00 2001 From: malinink Date: Wed, 21 Nov 2018 13:06:23 +0300 Subject: [PATCH 1/5] Add test case for wrong of.array.intems.enum validation --- tests/Constraints/OfPropertiesTest.php | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 17623f49..d3233308 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -213,7 +213,33 @@ public function getInvalidTests() } } }' - ) + ), + array( + '{"prop1": ["a", "b"]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string", + "enum": ["b","c"] + } + }, + { + "type": "array", + "items": { + "type": "string", + "enum": ["c","d"] + } + } + ] + } + } + }' + ), ); } From 433fa4328eb8fd91ad8ddb0a26a3ff7a99f79283 Mon Sep 17 00:00:00 2001 From: malinink Date: Wed, 21 Nov 2018 13:38:52 +0300 Subject: [PATCH 2/5] Revert "Add test case for wrong of.array.intems.enum validation" This reverts commit e0cb400de67eceb8923e1eeccdf21d507f93c0d4. --- tests/Constraints/OfPropertiesTest.php | 28 +------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index d3233308..17623f49 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -213,33 +213,7 @@ public function getInvalidTests() } } }' - ), - array( - '{"prop1": ["a", "b"]}', - '{ - "type": "object", - "properties": { - "prop1": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string", - "enum": ["b","c"] - } - }, - { - "type": "array", - "items": { - "type": "string", - "enum": ["c","d"] - } - } - ] - } - } - }' - ), + ) ); } From 1d81fa311189370f765d6132465e59ec2035f44c Mon Sep 17 00:00:00 2001 From: malinink Date: Wed, 21 Nov 2018 13:39:38 +0300 Subject: [PATCH 3/5] Provide more simple test, array.items.enum --- tests/Constraints/ArraysTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index dac14358..44112540 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"] + } + } + } + }' ) ); } From 700bcd3ba60d19aa9f2d832e475e15c88242e83f Mon Sep 17 00:00:00 2001 From: malinink Date: Wed, 21 Nov 2018 15:10:05 +0300 Subject: [PATCH 4/5] Add positive array.string.enum case --- tests/Constraints/ArraysTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index 44112540..61984a38 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -183,6 +183,21 @@ public function getValidTests() } } }' + ), + array( + '{"data": ["c", "c", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' ) ); } From 47756460e09df89d0e4a3d2ba7c9201dac72a431 Mon Sep 17 00:00:00 2001 From: malinink Date: Wed, 21 Nov 2018 15:11:40 +0300 Subject: [PATCH 5/5] Fix CollectionConstraint validateItems perfomance optimisation --- src/JsonSchema/Constraints/NumberConstraint.php | 5 +++++ src/JsonSchema/Constraints/StringConstraint.php | 5 +++++ 2 files changed, 10 insertions(+) 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); }