Skip to content

Commit 30fc4c3

Browse files
committed
recursive resolve reference
1 parent 4355d0c commit 30fc4c3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Constraint/Ref.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Ref implements Constraint
88
{
99
public $ref;
10-
public function __construct($ref, Schema $schema)
10+
public function __construct($ref, Schema $schema = null)
1111
{
1212
$this->ref = $ref;
1313
$this->schema = $schema;
@@ -16,6 +16,15 @@ public function __construct($ref, Schema $schema)
1616
/** @var Schema */
1717
private $schema;
1818

19+
/**
20+
* @param Schema $schema
21+
* @return Ref
22+
*/
23+
public function setSchema($schema)
24+
{
25+
$this->schema = $schema;
26+
return $this;
27+
}
1928

2029
/**
2130
* @return Schema

src/SchemaLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function dumpSchema(Schema $schema)
9191
return $contents;
9292
}
9393

94-
public function dumpSchemaDeeper(Schema $schema, $path)
94+
private function dumpSchemaDeeper(Schema $schema, $path)
9595
{
9696
$result = new \stdClass();
9797

@@ -324,6 +324,7 @@ private function resolveReference($referencePath)
324324
if ($referencePath === '#') {
325325
$ref = new Ref($referencePath, $this->rootSchema);
326326
} else {
327+
$ref = new Ref($referencePath);
327328
$path = explode('/', trim($referencePath, '#/'));
328329
$branch = &$this->rootData;
329330
while (!empty($path)) {
@@ -342,7 +343,7 @@ private function resolveReference($referencePath)
342343
throw new \Exception('Could not resolve ' . $referencePath . ': ' . $folder);
343344
}
344345
}
345-
$ref = new Ref($referencePath, $this->readSchema($branch));
346+
$ref->setSchema($this->readSchema($branch));
346347
}
347348
} else {
348349
$refParts = explode('#', $referencePath);

0 commit comments

Comments
 (0)