diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index d88c5361..3b0c8eb0 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -241,6 +241,7 @@ protected function applyDefaultValues(&$value, $schema, $path) if (isset($schema->properties) && LooseTypeCheck::isObject($value)) { // $value is an object or assoc array, and properties are defined - treat as an object foreach ($schema->properties as $currentProperty => $propertyDefinition) { + $propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition); if ( !LooseTypeCheck::propertyExists($value, $currentProperty) && property_exists($propertyDefinition, 'default') @@ -264,6 +265,7 @@ protected function applyDefaultValues(&$value, $schema, $path) } // $value is an array, and items are defined - treat as plain array foreach ($items as $currentItem => $itemDefinition) { + $itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition); if ( !array_key_exists($currentItem, $value) && property_exists($itemDefinition, 'default') diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index bcf90b2c..cc5eb909 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -121,12 +121,12 @@ public function getValidTests() ), array(// #15 infinite recursion via $ref (object) '{}', - '{"properties":{"propertyOne": {"$ref": "#","default": {}}}}', + '{"properties":{"propertyOne": {"$ref": "#","default": "valueOne"}}, "default": {}}', '{"propertyOne":{}}' ), array(// #16 infinite recursion via $ref (array) '[]', - '{"items":[{"$ref":"#","default":[]}]}', + '{"items":[{"$ref":"#","default":"valueOne"}], "default": []}', '[[]]' ), array(// #17 default top value does not overwrite defined null