Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/RefResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function updateResolutionScope($id)
{
$id = rtrim($id, '#'); // safe to trim because # in hashCode must be urlencoded to %23
$rootResolver = $this->rootResolver ? $this->rootResolver : $this;
if (strpos($id, '://') !== false) {
if ((strpos($id, '://') !== false) || 'urn:' === substr($id, 0, 4)) {
$prev = $rootResolver->setResolutionScope($id);
} else {
$prev = $rootResolver->setResolutionScope(Helper::resolveURI($rootResolver->resolutionScope, $id));
$id = Helper::resolveURI($rootResolver->resolutionScope, $id);
$prev = $rootResolver->setResolutionScope($id);
}

return $prev;
Expand Down Expand Up @@ -198,6 +199,8 @@ public function resolveReference($referencePath)
$refResolver->refProvider = $this->refProvider;
$refResolver->url = $url;
$rootResolver->setResolutionScope($url);
$options = new Context(); // todo pass real ctx here, v0.13.0
$rootResolver->preProcessReferences($rootData, $options);
}
}

Expand Down
41 changes: 41 additions & 0 deletions tests/resources/suite/issue66.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "urn:example:api:response-example",
"type": "object",
"additionalProperties": false,
"required": [
"confirmed",
"to_pay"
],
"definitions": {
"example_item": {
"type": "object",
"additionalProperties": false,
"required": [
"_type",
"count"
],
"properties": {
"_type": {
"$id": "#/definitions/example_item/properties/confirmed/properties/_type",
"type": "string",
"enum": [
"example_item"
]
},
"count": {
"$id": "#/definitions/example_item/properties/confirmed/properties/count",
"type": "integer"
}
}
}
},
"properties": {
"confirmed": {
"$ref": "#/definitions/example_item"
},
"to_pay": {
"$ref": "#/definitions/example_item"
}
}
}
33 changes: 33 additions & 0 deletions tests/src/PHPUnit/Suite/Issue66Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Swaggest\JsonSchema\Tests\PHPUnit\Suite;

use Swaggest\JsonSchema\Context;
use Swaggest\JsonSchema\RemoteRef\Preloaded;
use Swaggest\JsonSchema\Schema;

class Issue66Test extends \PHPUnit_Framework_TestCase
{
public function testIssue()
{
$schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json');
$schemaData = json_decode(file_get_contents($schemaPath));
$resolver = new Preloaded();
$resolver->setSchemaData($schemaPath, $schemaData);

$options = new Context($resolver);

$schema = Schema::import((object)['$ref' => $schemaPath], $options);
$res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}'));
$this->assertSame(123, $res->confirmed->count);
}

public function testDirectImport()
{
$schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json');
$schema = Schema::import($schemaPath);
$res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}'));
$this->assertSame(123, $res->confirmed->count);
}

}