Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for $ref on properties #317

Merged
merged 2 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function validateTypes($value, $schema = null, JsonPointer $path, $i = nu
if ($this->getTypeCheck()->isObject($value)) {
$this->checkObject(
$value,
isset($schema->properties) ? $schema->properties : $schema,
isset($schema->properties) ? $this->schemaStorage->resolveRefSchema($schema->properties) : $schema,
$path,
isset($schema->additionalProperties) ? $schema->additionalProperties : null,
isset($schema->patternProperties) ? $schema->patternProperties : null
Expand Down
22 changes: 22 additions & 0 deletions tests/SchemaStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()
$schemaStorage->resolveRef("$mainSchemaPath#/properties/car/properties/wheel")
);

// properties ref
$this->assertEquals(
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/yardproperties"),
$schemaStorage->resolveRef("$mainSchemaPath#/properties/yard/properties")
);

// local ref with overriding
$this->assertNotEquals(
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house/additionalProperties"),
Expand All @@ -77,6 +83,7 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house"),
$schemaStorage->resolveRef("$mainSchemaPath#/properties/house/properties/house")
);

$this->assertEquals(
$schemaStorage->resolveRef("$mainSchemaPath#/definitions/house"),
$schemaStorage->resolveRef("$mainSchemaPath#/properties/house/properties/house/properties/house")
Expand Down Expand Up @@ -123,6 +130,13 @@ private function getMainSchema()
'house' => (object) array(
'additionalProperties' => true,
'$ref' => '#/definitions/house'
),
'yard' => (object) array(
'type' => 'object',
'additionalProperties' => false,
'properties' => (object)[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array for PHP 5.3

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Fixed, thanks...

'$ref' => '#/definitions/yardproperties'
]
)
),
'definitions' => (object) array(
Expand All @@ -144,6 +158,14 @@ private function getMainSchema()
'$ref' => '#/definitions/house'
)
)
),
'yardproperties' => (object) array(
'tree'=>(object) array(
'type' => 'string'
),
'pool'=>(object) array(
'type' => 'string'
)
)
)
);
Expand Down