Skip to content

Commit 64f6b85

Browse files
Test that identifiers are not found inside unrecognized keywords
see json-schema-org/json-schema-spec#1097 (comment)
1 parent 09fd353 commit 64f6b85

File tree

4 files changed

+224
-0
lines changed

4 files changed

+224
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$id inside an unknown keyword is not a real identifier",
4+
"comment": "the implementation must not be confused by an $id in locations we do not know how to parse",
5+
"schema": {
6+
"$defs": {
7+
"id_in_unknown0": {
8+
"not": {
9+
"array_of_schemas": [
10+
{
11+
"$id": "https://localhost:1234/my_identifier.json",
12+
"type": "null"
13+
}
14+
]
15+
}
16+
},
17+
"real_id_in_schema": {
18+
"$id": "https://localhost:1234/my_identifier.json",
19+
"type": "string"
20+
},
21+
"id_in_unknown1": {
22+
"not": {
23+
"object_of_schemas": {
24+
"foo": {
25+
"$id": "https://localhost:1234/my_identifier.json",
26+
"type": "integer"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"anyOf": [
33+
{ "$ref": "#/$defs/id_in_unknown0" },
34+
{ "$ref": "#/$defs/id_in_unknown1" },
35+
{ "$ref": "https://localhost:1234/my_identifier.json" }
36+
]
37+
},
38+
"tests": [
39+
{
40+
"description": "type matches second anyOf, which has a real schema in it",
41+
"data": "a string",
42+
"valid": true
43+
},
44+
{
45+
"description": "type matches non-schema in first anyOf",
46+
"data": null,
47+
"valid": false
48+
},
49+
{
50+
"description": "type matches non-schema in third anyOf",
51+
"data": 1,
52+
"valid": false
53+
}
54+
]
55+
}
56+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$id inside an unknown keyword is not a real identifier",
4+
"comment": "the implementation must not be confused by an $id in locations we do not know how to parse",
5+
"schema": {
6+
"$defs": {
7+
"id_in_unknown0": {
8+
"not": {
9+
"array_of_schemas": [
10+
{
11+
"$id": "https://localhost:1234/my_identifier.json",
12+
"type": "null"
13+
}
14+
]
15+
}
16+
},
17+
"real_id_in_schema": {
18+
"$id": "https://localhost:1234/my_identifier.json",
19+
"type": "string"
20+
},
21+
"id_in_unknown1": {
22+
"not": {
23+
"object_of_schemas": {
24+
"foo": {
25+
"$id": "https://localhost:1234/my_identifier.json",
26+
"type": "integer"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"anyOf": [
33+
{ "$ref": "#/$defs/id_in_unknown0" },
34+
{ "$ref": "#/$defs/id_in_unknown1" },
35+
{ "$ref": "https://localhost:1234/my_identifier.json" }
36+
]
37+
},
38+
"tests": [
39+
{
40+
"description": "type matches second anyOf, which has a real schema in it",
41+
"data": "a string",
42+
"valid": true
43+
},
44+
{
45+
"description": "type matches non-schema in first anyOf",
46+
"data": null,
47+
"valid": false
48+
},
49+
{
50+
"description": "type matches non-schema in third anyOf",
51+
"data": 1,
52+
"valid": false
53+
}
54+
]
55+
}
56+
]

tests/draft6/unknownKeyword.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$id inside an unknown keyword is not a real identifier",
4+
"comment": "the implementation must not be confused by an $id in locations we do not know how to parse",
5+
"schema": {
6+
"$defs": {
7+
"id_in_unknown0": {
8+
"not": {
9+
"array_of_schemas": [
10+
{
11+
"$id": "https://localhost:1234/my_identifier.json",
12+
"type": "null"
13+
}
14+
]
15+
}
16+
},
17+
"real_id_in_schema": {
18+
"$id": "https://localhost:1234/my_identifier.json",
19+
"type": "string"
20+
},
21+
"id_in_unknown1": {
22+
"not": {
23+
"object_of_schemas": {
24+
"foo": {
25+
"$id": "https://localhost:1234/my_identifier.json",
26+
"type": "integer"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"anyOf": [
33+
{ "$ref": "#/$defs/id_in_unknown0" },
34+
{ "$ref": "#/$defs/id_in_unknown1" },
35+
{ "$ref": "https://localhost:1234/my_identifier.json" }
36+
]
37+
},
38+
"tests": [
39+
{
40+
"description": "type matches second anyOf, which has a real schema in it",
41+
"data": "a string",
42+
"valid": true
43+
},
44+
{
45+
"description": "type matches non-schema in first anyOf",
46+
"data": null,
47+
"valid": false
48+
},
49+
{
50+
"description": "type matches non-schema in third anyOf",
51+
"data": 1,
52+
"valid": false
53+
}
54+
]
55+
}
56+
]

tests/draft7/unknownKeyword.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$id inside an unknown keyword is not a real identifier",
4+
"comment": "the implementation must not be confused by an $id in locations we do not know how to parse",
5+
"schema": {
6+
"$defs": {
7+
"id_in_unknown0": {
8+
"not": {
9+
"array_of_schemas": [
10+
{
11+
"$id": "https://localhost:1234/my_identifier.json",
12+
"type": "null"
13+
}
14+
]
15+
}
16+
},
17+
"real_id_in_schema": {
18+
"$id": "https://localhost:1234/my_identifier.json",
19+
"type": "string"
20+
},
21+
"id_in_unknown1": {
22+
"not": {
23+
"object_of_schemas": {
24+
"foo": {
25+
"$id": "https://localhost:1234/my_identifier.json",
26+
"type": "integer"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"anyOf": [
33+
{ "$ref": "#/$defs/id_in_unknown0" },
34+
{ "$ref": "#/$defs/id_in_unknown1" },
35+
{ "$ref": "https://localhost:1234/my_identifier.json" }
36+
]
37+
},
38+
"tests": [
39+
{
40+
"description": "type matches second anyOf, which has a real schema in it",
41+
"data": "a string",
42+
"valid": true
43+
},
44+
{
45+
"description": "type matches non-schema in first anyOf",
46+
"data": null,
47+
"valid": false
48+
},
49+
{
50+
"description": "type matches non-schema in third anyOf",
51+
"data": 1,
52+
"valid": false
53+
}
54+
]
55+
}
56+
]

0 commit comments

Comments
 (0)