Skip to content

Commit b723216

Browse files
authored
Merge pull request #34 from swaggest/issue-33
wrong absolute uri resolving, fixes #33
2 parents ee99622 + b6909aa commit b723216

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function resolveURI($parent, $current)
5555
} elseif ('/' === substr($currentParts[0], 0, 1)) {
5656
$resultParts[0] = $currentParts[0];
5757
if ($pos = strpos($parentParts[0], '://')) {
58-
$resultParts[0] = substr($parentParts[0], 0, strpos($parentParts[0], '/', $pos)) . $resultParts[0];
58+
$resultParts[0] = substr($parentParts[0], 0, strpos($parentParts[0], '/', $pos + 3)) . $resultParts[0];
5959
}
6060
} elseif (false !== $pos = strrpos($parentParts[0], '/')) {
6161
$resultParts[0] = substr($parentParts[0], 0, $pos + 1) . $currentParts[0];
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Swaggest\JsonSchema\Tests\PHPUnit\Suite;
4+
5+
6+
use Swaggest\JsonSchema\Context;
7+
use Swaggest\JsonSchema\InvalidValue;
8+
use Swaggest\JsonSchema\RemoteRef\Preloaded;
9+
use Swaggest\JsonSchema\Schema;
10+
11+
class Issue33Test extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testRef() {
14+
$schemaJson = <<<'JSON'
15+
{
16+
"id": "https://some-domain/Entity/Foo/Bar/Baz/1.1#",
17+
"$schema": "http://json-schema.org/draft-04/schema#",
18+
"allOf": [
19+
{
20+
"$ref": "/Entity/1.1#"
21+
},
22+
{
23+
"type": "object",
24+
"properties": {
25+
"appId": {
26+
"$ref": "/definition/AppID/1.1#"
27+
},
28+
"date": {
29+
"$ref": "/definition/Date/1.1#"
30+
},
31+
"timestamp": {
32+
"$ref": "/definition/Date/UnixTimestamp/1.1#"
33+
}
34+
}
35+
}
36+
]
37+
}
38+
JSON;
39+
$provider = new Preloaded();
40+
$provider->setSchemaData("https://some-domain/Entity/1.1", json_decode('{}'));
41+
$provider->setSchemaData("https://some-domain/definition/AppID/1.1", json_decode('{"type":"integer"}'));
42+
$provider->setSchemaData("https://some-domain/definition/Date/1.1", json_decode('{}'));
43+
$provider->setSchemaData("https://some-domain/definition/Date/UnixTimestamp/1.1", json_decode('{}'));
44+
45+
$options = new Context();
46+
$options->setRemoteRefProvider($provider);
47+
$schema = Schema::import(json_decode($schemaJson), $options);
48+
$schema->in(json_decode('{"appId":123}'));
49+
$this->setExpectedException(get_class(new InvalidValue()));
50+
$schema->in(json_decode('{"appId":"some-string"}'));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)