Skip to content

Commit 5550f3c

Browse files
bighappyfaceerayd
authored andcommitted
Merge pull request jsonrainbow#494 from erayd/apply-ref-default
[BUGFIX] Apply defaults in $ref'ed property / item definitions
1 parent d9ccbbb commit 5550f3c

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
@@ -243,6 +243,7 @@ protected function applyDefaultValues(&$value, $schema, $path)
243243
if (isset($schema->properties) && LooseTypeCheck::isObject($value)) {
244244
// $value is an object or assoc array, and properties are defined - treat as an object
245245
foreach ($schema->properties as $currentProperty => $propertyDefinition) {
246+
$propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition);
246247
if (
247248
!LooseTypeCheck::propertyExists($value, $currentProperty)
248249
&& property_exists($propertyDefinition, 'default')
@@ -266,6 +267,7 @@ protected function applyDefaultValues(&$value, $schema, $path)
266267
}
267268
// $value is an array, and items are defined - treat as plain array
268269
foreach ($items as $currentItem => $itemDefinition) {
270+
$itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition);
269271
if (
270272
!array_key_exists($currentItem, $value)
271273
&& 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)