Skip to content

Commit d4ca223

Browse files
committed
Reproduce issue #66
1 parent 0db6c01 commit d4ca223

File tree

2 files changed

+58
-39
lines changed

2 files changed

+58
-39
lines changed

tests/resources/suite/issue66.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "urn:example:api:response-example",
4+
"type": "object",
5+
"additionalProperties": false,
6+
"required": [
7+
"confirmed",
8+
"to_pay"
9+
],
10+
"definitions": {
11+
"example_item": {
12+
"type": "object",
13+
"additionalProperties": false,
14+
"required": [
15+
"_type",
16+
"count"
17+
],
18+
"properties": {
19+
"_type": {
20+
"$id": "#/definitions/example_item/properties/confirmed/properties/_type",
21+
"type": "string",
22+
"enum": [
23+
"example_item"
24+
]
25+
},
26+
"count": {
27+
"$id": "#/definitions/example_item/properties/confirmed/properties/count",
28+
"type": "integer"
29+
}
30+
}
31+
}
32+
},
33+
"properties": {
34+
"confirmed": {
35+
"$ref": "#/definitions/example_item"
36+
},
37+
"to_pay": {
38+
"$ref": "#/definitions/example_item"
39+
}
40+
}
41+
}

tests/src/PHPUnit/Suite/Issue66Test.php

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,30 @@
22

33
namespace Swaggest\JsonSchema\Tests\PHPUnit\Suite;
44

5+
use Swaggest\JsonSchema\Context;
6+
use Swaggest\JsonSchema\RemoteRef\Preloaded;
57
use Swaggest\JsonSchema\Schema;
68

79
class Issue66Test extends \PHPUnit_Framework_TestCase
810
{
911
public function testIssue()
1012
{
11-
$schemaData = json_decode(<<<'JSON'
12-
{
13-
"$schema": "http://json-schema.org/draft-07/schema#",
14-
"$id": "urn:example:api:response-example",
15-
"type": "object",
16-
"additionalProperties": false,
17-
"required": ["confirmed", "to_pay"],
18-
"definitions": {
19-
"example_item": {
20-
"type": "object",
21-
"additionalProperties": false,
22-
"required": [
23-
"_type",
24-
"count"
25-
],
26-
"properties": {
27-
"_type": {
28-
"$id": "#/definitions/example_item/properties/confirmed/properties/_type",
29-
"type": "string",
30-
"enum": ["example_item"]
31-
},
32-
"count": {
33-
"$id": "#/definitions/example_item/properties/confirmed/properties/count",
34-
"type": "integer"
35-
}
36-
}
37-
}
38-
},
39-
"properties": {
40-
"confirmed": {
41-
"$ref": "#/definitions/example_item"
42-
},
43-
"to_pay": {
44-
"$ref": "#/definitions/example_item"
45-
}
13+
$schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json');
14+
$schemaData = json_decode(file_get_contents($schemaPath));
15+
$resolver = new Preloaded();
16+
$resolver->setSchemaData($schemaPath, $schemaData);
17+
18+
$options = new Context($resolver);
19+
20+
$schema = Schema::import((object)['$ref' => $schemaPath], $options);
21+
$res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}'));
22+
$this->assertSame(123, $res->confirmed->count);
4623
}
47-
}
48-
JSON
49-
);
50-
$schema = Schema::import($schemaData);
24+
25+
public function testDirectImport()
26+
{
27+
$schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json');
28+
$schema = Schema::import($schemaPath);
5129
$res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}'));
5230
$this->assertSame(123, $res->confirmed->count);
5331
}

0 commit comments

Comments
 (0)