Skip to content
Closed
Changes from all commits
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
18 changes: 7 additions & 11 deletions src/JsonSchema/RefResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getUriRetriever()
* @param object $schema JSON Schema to flesh out
* @param string $sourceUri URI where this schema was located
*/
public function resolve($schema, $sourceUri = null)
public function resolve($schema, $sourceUri = null, $rootSchema = null)
{
if (self::$depth > self::$maxDepth) {
self::$depth = 0;
Expand All @@ -116,12 +116,8 @@ public function resolve($schema, $sourceUri = null)
$sourceUri = $schema->id;
}

if (null === $this->rootSchema) {
$this->rootSchema = $schema;
}

// Resolve $ref first
$this->resolveRef($schema, $sourceUri);
$this->resolveRef($schema, $sourceUri, $rootSchema ?: $schema);

// These properties are just schemas
// eg. items can be a schema or an array of schemas
Expand Down Expand Up @@ -159,7 +155,7 @@ public function resolveArrayOfSchemas($schema, $propertyName, $sourceUri)
}

foreach ($schema->$propertyName as $possiblySchema) {
$this->resolve($possiblySchema, $sourceUri);
$this->resolve($possiblySchema, $sourceUri, $schema);
}
}

Expand All @@ -178,7 +174,7 @@ public function resolveObjectOfSchemas($schema, $propertyName, $sourceUri)
}

foreach (get_object_vars($schema->$propertyName) as $possiblySchema) {
$this->resolve($possiblySchema, $sourceUri);
$this->resolve($possiblySchema, $sourceUri, $schema);
}
}

Expand All @@ -196,7 +192,7 @@ public function resolveProperty($schema, $propertyName, $sourceUri)
return;
}

$this->resolve($schema->$propertyName, $sourceUri);
$this->resolve($schema->$propertyName, $sourceUri, $schema);
}

/**
Expand All @@ -207,7 +203,7 @@ public function resolveProperty($schema, $propertyName, $sourceUri)
* @param object $schema JSON Schema to flesh out
* @param string $sourceUri URI where this schema was located
*/
public function resolveRef($schema, $sourceUri)
public function resolveRef($schema, $sourceUri, $rootSchema = null)
{
$ref = '$ref';

Expand All @@ -232,7 +228,7 @@ public function resolveRef($schema, $sourceUri)
if (!empty($refDoc)) {
$refSchema = $this->fetchRef($refDoc, $sourceUri);
} else {
$refSchema = $this->rootSchema;
$refSchema = $rootSchema ?: $schema;
}

if (null !== $refPath) {
Expand Down