Skip to content

Commit 808a460

Browse files
authored
Merge pull request #371 from harrel56/chore/update-test-suite-20260324-160238
chore(test-suite): incremental test suite update from upstream
2 parents 6e332ca + 9bbc7a1 commit 808a460

38 files changed

Lines changed: 970 additions & 3 deletions

File tree

lib/src/main/java/dev/harrel/jsonschema/FormatEvaluatorFactory.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.sanctionco.jmail.net.InternetProtocolAddress;
55

66
import java.net.URI;
7+
import java.net.URISyntaxException;
78
import java.time.format.DateTimeFormatter;
89
import java.util.*;
910
import java.util.function.Consumer;
@@ -225,10 +226,18 @@ private static void uriOperator(String value) throws FormatException {
225226

226227
private static void iriOperator(String value) throws FormatException {
227228
try {
228-
if (!URI.create(value).isAbsolute()) {
229+
URI uri = URI.create(value);
230+
if (!uri.isAbsolute()) {
229231
throw new FormatException(String.format("\"%s\" is relative", value));
230232
}
231-
} catch (RuntimeException e) {
233+
/*
234+
* https://www.rfc-editor.org/rfc/rfc3986.html#appendix-A
235+
* reg-name cannot contain unescaped ':', thus treating it as a server authority
236+
*/
237+
if (uri.getRawSchemeSpecificPart().contains(":")) {
238+
uri.parseServerAuthority();
239+
}
240+
} catch (URISyntaxException | RuntimeException e) {
232241
throw new FormatException(e.getMessage());
233242
}
234243
}

lib/src/testFixtures/resources/suite-annotation/core.json

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,108 @@
2525
]
2626
}
2727
]
28+
},
29+
{
30+
"description": "`$dynamicRef` resolves to `$dynamicAnchor`",
31+
"compatibility": "2020",
32+
"schema": {
33+
"$dynamicRef": "#foo",
34+
"$defs": {
35+
"foo": {
36+
"$dynamicAnchor": "foo",
37+
"title": "Foo"
38+
}
39+
}
40+
},
41+
"tests": [
42+
{
43+
"instance": "bar",
44+
"assertions": [
45+
{
46+
"location": "",
47+
"keyword": "title",
48+
"expected": {
49+
"#/$defs/foo": "Foo"
50+
}
51+
}
52+
]
53+
}
54+
]
55+
},
56+
{
57+
"description": "`$dynamicRef` resolves to different `$dynamicAnchor`s depending on dynamic path",
58+
"compatibility": "2020",
59+
"schema": {
60+
"$id": "https://test.json-schema.org/dynamic-ref-annotation/main",
61+
"if": {
62+
"properties": { "kindOfList": { "const": "numbers" } },
63+
"required": ["kindOfList"]
64+
},
65+
"then": { "$ref": "numberList" },
66+
"else": { "$ref": "stringList" },
67+
"$defs": {
68+
"genericList": {
69+
"$id": "genericList",
70+
"properties": {
71+
"list": {
72+
"items": { "$dynamicRef": "#itemType" }
73+
}
74+
},
75+
"$defs": {
76+
"defaultItemType": {
77+
"$dynamicAnchor": "itemType"
78+
}
79+
}
80+
},
81+
"numberList": {
82+
"$id": "numberList",
83+
"$defs": {
84+
"itemType": {
85+
"$dynamicAnchor": "itemType",
86+
"title": "Number Item"
87+
}
88+
},
89+
"$ref": "genericList"
90+
},
91+
"stringList": {
92+
"$id": "stringList",
93+
"$defs": {
94+
"itemType": {
95+
"$dynamicAnchor": "itemType",
96+
"title": "String Item"
97+
}
98+
},
99+
"$ref": "genericList"
100+
}
101+
}
102+
},
103+
"tests": [
104+
{
105+
"instance": { "kindOfList": "numbers", "list": [1] },
106+
"assertions": [
107+
{
108+
"location": "/list/0",
109+
"keyword": "title",
110+
"expected": {
111+
"#/$defs/numberList/$defs/itemType": "Number Item"
112+
}
113+
}
114+
]
115+
},
116+
{
117+
"instance": { "kindOfList": "strings", "list": ["foo"] },
118+
"assertions": [
119+
{
120+
"location": "/list/0",
121+
"keyword": "title",
122+
"expected": {
123+
"#/$defs/stringList/$defs/itemType": "String Item"
124+
}
125+
}
126+
]
127+
}
128+
]
28129
}
130+
29131
]
30-
}
132+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"description": "URI format",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/2020-12/schema",
6+
"format": "uri"
7+
},
8+
"tests": [
9+
{
10+
"description": "registry based authority can contain encoded ':'",
11+
"data": "https://example.com%3Aabc",
12+
"valid": true
13+
}
14+
]
15+
}
16+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"description": "URI format",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/2020-12/schema",
6+
"format": "uri"
7+
},
8+
"tests": [
9+
{
10+
"description": "registry based authority can contain encoded ':'",
11+
"data": "https://example.com%3Aabc",
12+
"valid": true
13+
}
14+
]
15+
}
16+
]

lib/src/testFixtures/resources/suite-yaml/tests/draft2019-09/enum.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,26 @@
261261
- description: do not match string lacking nul
262262
data: hellothere
263263
valid: false
264+
- description: empty enum
265+
schema:
266+
$schema: https://json-schema.org/draft/2019-09/schema
267+
enum: []
268+
tests:
269+
- description: string is invalid
270+
data: foo
271+
valid: false
272+
- description: number is invalid
273+
data: 42
274+
valid: false
275+
- description: null is invalid
276+
data: null
277+
valid: false
278+
- description: object is invalid
279+
data: {}
280+
valid: false
281+
- description: array is invalid
282+
data: []
283+
valid: false
284+
- description: boolean is invalid
285+
data: false
286+
valid: false

lib/src/testFixtures/resources/suite-yaml/tests/draft2019-09/maxContains.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,18 @@
8181
- 1
8282
- 1
8383
valid: false
84+
- description: maxContains = 0 with minContains = 0
85+
schema:
86+
$schema: https://json-schema.org/draft/2019-09/schema
87+
contains:
88+
const: 1
89+
minContains: 0
90+
maxContains: 0
91+
tests:
92+
- description: empty array
93+
data: []
94+
valid: true
95+
- description: one matching item
96+
data:
97+
- 1
98+
valid: false

lib/src/testFixtures/resources/suite-yaml/tests/draft2019-09/optional/format/duration.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- description: validation of duration strings
2+
comment: RFC 3339 Appendix A defines the ABNF grammar for ISO-8601 durations used by JSON Schema format 'duration'. These tests enforce only the syntax defined by that grammar.
23
schema:
34
$schema: https://json-schema.org/draft/2019-09/schema
45
format: duration
@@ -81,3 +82,52 @@
8182
- description: element without unit
8283
data: P1
8384
valid: false
85+
- description: all date and time components
86+
data: P1Y2M3DT4H5M6S
87+
valid: true
88+
- description: date components only
89+
data: P1Y2M3D
90+
valid: true
91+
- description: time components only
92+
data: PT1H2M3S
93+
valid: true
94+
- description: month and day
95+
data: P1M2D
96+
valid: true
97+
- description: hour and minute
98+
data: PT1H30M
99+
valid: true
100+
- description: multi-digit values in all components
101+
data: P10Y10M10DT10H10M10S
102+
valid: true
103+
- description: fractional duration is not allowed by RFC 3339 ABNF
104+
comment: numeric components use 1*DIGIT where DIGIT = %x30-39; '.' is not allowed
105+
data: PT0.5S
106+
valid: false
107+
- description: leading whitespace is invalid
108+
data: ' P1D'
109+
valid: false
110+
- description: trailing whitespace is invalid
111+
data: 'P1D '
112+
valid: false
113+
- description: empty string is invalid
114+
data: ""
115+
valid: false
116+
- description: years and months can appear without days
117+
data: P1Y2M
118+
valid: true
119+
- description: years and days cannot appear without months
120+
data: P1Y2D
121+
valid: false
122+
- description: months and days can appear without years
123+
data: P1M2D
124+
valid: true
125+
- description: hours and minutes can appear without seconds
126+
data: PT1H2M
127+
valid: true
128+
- description: hours and seconds cannot appear without minutes
129+
data: PT1H2S
130+
valid: false
131+
- description: minutes and seconds can appear without hour
132+
data: PT1M2S
133+
valid: true

lib/src/testFixtures/resources/suite-yaml/tests/draft2019-09/optional/format/email.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@
5454
- description: full "From" header is invalid
5555
data: '"Winston Smith" <winston.smith@recdep.minitrue> (Records Department)'
5656
valid: false
57+
- description: local part is required
58+
data: '@example.com'
59+
valid: false
60+
- description: domain is required
61+
data: joe.bloggs@
62+
valid: false
63+
- description: unquoted space in local part is invalid
64+
data: joe bloggs@example.com
65+
valid: false

lib/src/testFixtures/resources/suite-yaml/tests/draft2019-09/optional/format/uri.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,21 @@
119119
comment: 'RFC 3986, Section 3.2.2: Fallback to reg-name allows digits and dots.'
120120
data: http://999.999.999.999/
121121
valid: true
122+
- description: invalid percent-encoding with non-hex digits
123+
data: http://example.com/%6G
124+
valid: false
125+
- description: incomplete percent-encoding triplet
126+
data: http://example.com/%A
127+
valid: false
128+
- description: lone percent sign is invalid
129+
data: http://example.com/%
130+
valid: false
131+
- description: scheme must start with a letter
132+
data: 1http://example.com
133+
valid: false
134+
- description: invalid character in scheme
135+
data: ht_tp://example.com
136+
valid: false
137+
- description: non-numeric port is invalid
138+
data: http://example.com:abc/path
139+
valid: false

lib/src/testFixtures/resources/suite-yaml/tests/draft2020-12/enum.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,26 @@
261261
- description: do not match string lacking nul
262262
data: hellothere
263263
valid: false
264+
- description: empty enum
265+
schema:
266+
$schema: https://json-schema.org/draft/2020-12/schema
267+
enum: []
268+
tests:
269+
- description: string is invalid
270+
data: foo
271+
valid: false
272+
- description: number is invalid
273+
data: 42
274+
valid: false
275+
- description: null is invalid
276+
data: null
277+
valid: false
278+
- description: object is invalid
279+
data: {}
280+
valid: false
281+
- description: array is invalid
282+
data: []
283+
valid: false
284+
- description: boolean is invalid
285+
data: false
286+
valid: false

0 commit comments

Comments
 (0)