Skip to content

Commit d701d8f

Browse files
shmaxbighappyface
authored andcommitted
Add support for $ref on properties (#317)
* add support for on properties * use classic array syntax
1 parent 0bbaac8 commit d701d8f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function validateTypes($value, $schema = null, JsonPointer $path, $i = nu
6060
if ($this->getTypeCheck()->isObject($value)) {
6161
$this->checkObject(
6262
$value,
63-
isset($schema->properties) ? $schema->properties : $schema,
63+
isset($schema->properties) ? $this->schemaStorage->resolveRefSchema($schema->properties) : $schema,
6464
$path,
6565
isset($schema->additionalProperties) ? $schema->additionalProperties : null,
6666
isset($schema->patternProperties) ? $schema->patternProperties : null

tests/SchemaStorageTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()
6262
$schemaStorage->resolveRef("$mainSchemaPath#/properties/car/properties/wheel")
6363
);
6464

65+
// properties ref
66+
$this->assertEquals(
67+
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/yardproperties"),
68+
$schemaStorage->resolveRef("$mainSchemaPath#/properties/yard/properties")
69+
);
70+
6571
// local ref with overriding
6672
$this->assertNotEquals(
6773
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house/additionalProperties"),
@@ -77,6 +83,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()
7783
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house"),
7884
$schemaStorage->resolveRef("$mainSchemaPath#/properties/house/properties/house")
7985
);
86+
8087
$this->assertEquals(
8188
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house"),
8289
$schemaStorage->resolveRef("$mainSchemaPath#/properties/house/properties/house/properties/house")
@@ -123,6 +130,13 @@ private function getMainSchema()
123130
'house' => (object) array(
124131
'additionalProperties' => true,
125132
'$ref' => '#/definitions/house'
133+
),
134+
'yard' => (object) array(
135+
'type' => 'object',
136+
'additionalProperties' => false,
137+
'properties' => (object) array(
138+
'$ref' => '#/definitions/yardproperties'
139+
)
126140
)
127141
),
128142
'definitions' => (object) array(
@@ -144,6 +158,14 @@ private function getMainSchema()
144158
'$ref' => '#/definitions/house'
145159
)
146160
)
161+
),
162+
'yardproperties' => (object) array(
163+
'tree'=>(object) array(
164+
'type' => 'string'
165+
),
166+
'pool'=>(object) array(
167+
'type' => 'string'
168+
)
147169
)
148170
)
149171
);

0 commit comments

Comments
 (0)