Skip to content

Commit 06186e5

Browse files
authored
Merge pull request #44 from swaggest/ref-testcase
self-reference test case
2 parents eca3551 + 27c7eb0 commit 06186e5

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

tests/resources/suite/ref.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
{
3+
"description": "remote ref",
34
"schema": {
45
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
56
},
@@ -15,5 +16,63 @@
1516
"valid": false
1617
}
1718
]
19+
},
20+
{
21+
"description": "enum-terminated self-reference",
22+
"schema": {
23+
"anyOf": [
24+
{
25+
"$ref": "#/definitions/Foo"
26+
}
27+
],
28+
"definitions": {
29+
"Foo": {
30+
"oneOf": [
31+
{
32+
"enum": [
33+
"A",
34+
"B"
35+
]
36+
},
37+
{
38+
"type": "object",
39+
"additionalProperties": {
40+
"$ref": "#/definitions/Foo"
41+
}
42+
}
43+
]
44+
}
45+
}
46+
},
47+
"tests": [
48+
{
49+
"description": "valid against enum",
50+
"data": {
51+
"test": "A",
52+
"test1": "B",
53+
"test2": {
54+
"test4": "A",
55+
"test5": {
56+
"test6": "B"
57+
}
58+
}
59+
},
60+
"valid": true
61+
},
62+
{
63+
"description": "invalid against enum",
64+
"data": {
65+
"test": "A",
66+
"test1": "B",
67+
"test2": {
68+
"test4": "A",
69+
"test5": {
70+
"test6": "C"
71+
}
72+
}
73+
},
74+
"valid": false
75+
}
76+
]
1877
}
1978
]

tests/resources/suite/refRemote.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
]
160160
},
161161
{
162+
"description": "remote reference with url fragment",
162163
"schema": {
163164
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
164165
},

tests/src/PHPUnit/ClassStructure/ExportSchemaTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Swaggest\JsonSchema\Tests\PHPUnit\ClassStructure;
44

55

6+
use Swaggest\JsonSchema\Context;
7+
use Swaggest\JsonSchema\RemoteRef\Preloaded;
68
use Swaggest\JsonSchema\Schema;
79
use Swaggest\JsonSchema\Tests\Helper\DbId;
810
use Swaggest\JsonSchema\Tests\Helper\DeepRefRoot;
@@ -125,7 +127,7 @@ public function testDeepRefSchema()
125127
JSON;
126128
$schemaData = json_decode($schemaJson);
127129

128-
$schema = Schema::import($schemaData);
130+
$schema = Schema::import($schemaData, new Context(new Preloaded()));
129131
$exported = Schema::export($schema);
130132
$this->assertSame($schemaJson, json_encode($exported, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES));
131133
}

0 commit comments

Comments
 (0)