From 1ad06ab3ce39578337185a46ddb56ebaddb61517 Mon Sep 17 00:00:00 2001 From: wlalele Date: Mon, 2 Jul 2018 18:27:15 +0200 Subject: [PATCH 1/3] Add a failing test about items being an array I think this test should be working, just like the 20 or the 21, it is quite similar but still produces a wrong result. --- tests/Constraints/DefaultPropertiesTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index cc5eb909..2c277712 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -154,6 +154,11 @@ public function getValidTests() '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', '[{"propertyOne":"valueOne"}]' ), + array(// #21b items is an array of schema + '[{}]', + '{"items":[{"properties":{"propertyOne":{"default":"valueOne"}}}]}', + '[{"propertyOne":"valueOne"}]' + ), array(// #22 if items is not an array, it does not create a new item '[]', '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', From 5bd5ac32dfbb60ec30776331a1cd70b45650945d Mon Sep 17 00:00:00 2001 From: alex-pex Date: Mon, 2 Jul 2018 18:51:23 +0200 Subject: [PATCH 2/3] Fix default value, with an array of item schemas --- src/JsonSchema/Constraints/UndefinedConstraint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index 02f14c0b..a1334a7b 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -280,8 +280,8 @@ protected function applyDefaultValues(&$value, $schema, $path) } else { $value[$currentItem] = $itemDefinition->default; } + $path->setFromDefault(); } - $path->setFromDefault(); } } elseif ( $value instanceof self From 079f529c2b40c3bd72c008a18ae15024cbcae18d Mon Sep 17 00:00:00 2001 From: wlalele Date: Tue, 3 Jul 2018 10:08:10 +0200 Subject: [PATCH 3/3] Move and set a real number to the new test --- tests/Constraints/DefaultPropertiesTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index 2c277712..1614d46c 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -154,11 +154,6 @@ public function getValidTests() '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', '[{"propertyOne":"valueOne"}]' ), - array(// #21b items is an array of schema - '[{}]', - '{"items":[{"properties":{"propertyOne":{"default":"valueOne"}}}]}', - '[{"propertyOne":"valueOne"}]' - ), array(// #22 if items is not an array, it does not create a new item '[]', '{"items":{"properties":{"propertyOne":{"default":"valueOne"}}}}', @@ -169,6 +164,11 @@ public function getValidTests() '{"items":{"default":"b"}, "minItems": 3}', '["a","b","b"]' ), + array(// #24 items is an array of schema + '[{}]', + '{"items":[{"properties":{"propertyOne":{"default":"valueOne"}}}]}', + '[{"propertyOne":"valueOne"}]' + ), ); }