Skip to content

Commit dd084db

Browse files
authored
Merge pull request #494 from erayd/apply-ref-default
[BUGFIX] Apply defaults in $ref'ed property / item definitions
2 parents 7d7f43a + 8a5ac14 commit dd084db

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ protected function applyDefaultValues(&$value, $schema, $path)
241241
if (isset($schema->properties) && LooseTypeCheck::isObject($value)) {
242242
// $value is an object or assoc array, and properties are defined - treat as an object
243243
foreach ($schema->properties as $currentProperty => $propertyDefinition) {
244+
$propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition);
244245
if (
245246
!LooseTypeCheck::propertyExists($value, $currentProperty)
246247
&& property_exists($propertyDefinition, 'default')
@@ -264,6 +265,7 @@ protected function applyDefaultValues(&$value, $schema, $path)
264265
}
265266
// $value is an array, and items are defined - treat as plain array
266267
foreach ($items as $currentItem => $itemDefinition) {
268+
$itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition);
267269
if (
268270
!array_key_exists($currentItem, $value)
269271
&& property_exists($itemDefinition, 'default')

tests/Constraints/DefaultPropertiesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ public function getValidTests()
121121
),
122122
array(// #15 infinite recursion via $ref (object)
123123
'{}',
124-
'{"properties":{"propertyOne": {"$ref": "#","default": {}}}}',
124+
'{"properties":{"propertyOne": {"$ref": "#","default": "valueOne"}}, "default": {}}',
125125
'{"propertyOne":{}}'
126126
),
127127
array(// #16 infinite recursion via $ref (array)
128128
'[]',
129-
'{"items":[{"$ref":"#","default":[]}]}',
129+
'{"items":[{"$ref":"#","default":"valueOne"}], "default": []}',
130130
'[[]]'
131131
),
132132
array(// #17 default top value does not overwrite defined null

0 commit comments

Comments
 (0)