Skip to content

Commit 3cd57fe

Browse files
committed
Fix for retrieving a JSON array from a uri
1 parent 1235d2e commit 3cd57fe

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/JsonSchema/Uri/UriRetriever.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ public function retrieve($uri, $baseUri = null)
150150

151151
// Use the JSON pointer if specified
152152
$jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
153-
$jsonSchema->id = $resolvedUri;
153+
154+
if ($jsonSchema instanceof \StdClass) {
155+
$jsonSchema->id = $resolvedUri;
156+
}
154157

155158
return $jsonSchema;
156159
}

tests/JsonSchema/Tests/RefResolverTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,25 @@ public function testFetchRefRelativeAnchor()
287287
);
288288
}
289289

290+
public function testFetchRefArray()
291+
{
292+
$retr = new \JsonSchema\Uri\Retrievers\PredefinedArray(
293+
array(
294+
'http://example.org/array' => <<<JSN
295+
array(1,2,3)
296+
JSN
297+
)
298+
);
299+
300+
$res = new \JsonSchema\RefResolver();
301+
$res->getUriRetriever()->setUriRetriever($retr);
302+
303+
$this->assertEquals(
304+
array(1,2,3),
305+
$res->fetchRef('http://example.org/array', 'http://example.org/array')
306+
);
307+
}
308+
290309
public function testSetGetUriRetriever()
291310
{
292311
$retriever = new \JsonSchema\Uri\UriRetriever;

0 commit comments

Comments
 (0)