@hyperjump/json-schema 1.16.4 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +105 -16
  2. package/annotations/annotated-instance.js +1 -1
  3. package/draft-04/format.js +31 -0
  4. package/draft-04/index.js +3 -1
  5. package/draft-06/format.js +34 -0
  6. package/draft-06/index.js +3 -1
  7. package/draft-07/format.js +42 -0
  8. package/draft-07/index.js +3 -1
  9. package/draft-2019-09/format-assertion.js +44 -0
  10. package/draft-2019-09/format.js +44 -0
  11. package/draft-2019-09/index.js +5 -1
  12. package/draft-2020-12/format-assertion.js +43 -0
  13. package/draft-2020-12/index.js +6 -2
  14. package/formats/handlers/date-time.js +7 -0
  15. package/formats/handlers/date.js +7 -0
  16. package/formats/handlers/draft-04/hostname.js +7 -0
  17. package/formats/handlers/duration.js +7 -0
  18. package/formats/handlers/email.js +7 -0
  19. package/formats/handlers/hostname.js +7 -0
  20. package/formats/handlers/idn-email.js +7 -0
  21. package/formats/handlers/idn-hostname.js +7 -0
  22. package/formats/handlers/ipv4.js +7 -0
  23. package/formats/handlers/ipv6.js +7 -0
  24. package/formats/handlers/iri-reference.js +7 -0
  25. package/formats/handlers/iri.js +7 -0
  26. package/formats/handlers/json-pointer.js +7 -0
  27. package/formats/handlers/regex.js +7 -0
  28. package/formats/handlers/relative-json-pointer.js +7 -0
  29. package/formats/handlers/time.js +7 -0
  30. package/formats/handlers/uri-reference.js +7 -0
  31. package/formats/handlers/uri-template.js +7 -0
  32. package/formats/handlers/uri.js +7 -0
  33. package/formats/handlers/uuid.js +7 -0
  34. package/formats/index.js +12 -0
  35. package/formats/lite.js +43 -0
  36. package/lib/configuration.js +7 -2
  37. package/lib/experimental.d.ts +8 -0
  38. package/lib/experimental.js +1 -0
  39. package/lib/keywords/dynamicRef.js +1 -1
  40. package/lib/keywords/format.js +35 -2
  41. package/lib/keywords.js +25 -3
  42. package/openapi-3-0/index.js +1 -1
  43. package/openapi-3-1/index.d.ts +66 -17
  44. package/openapi-3-1/schema-draft-2019-09.js +1 -1
  45. package/openapi-3-1/schema-draft-2020-12.js +1 -1
  46. package/openapi-3-2/dialect/base.js +2 -2
  47. package/openapi-3-2/index.d.ts +326 -2
  48. package/openapi-3-2/index.js +2 -4
  49. package/openapi-3-2/meta/base.js +30 -5
  50. package/openapi-3-2/schema-base.js +2 -3
  51. package/openapi-3-2/schema-draft-04.js +2 -2
  52. package/openapi-3-2/schema-draft-06.js +2 -2
  53. package/openapi-3-2/schema-draft-07.js +2 -2
  54. package/openapi-3-2/schema-draft-2019-09.js +3 -3
  55. package/openapi-3-2/schema-draft-2020-12.js +3 -3
  56. package/openapi-3-2/schema.js +1661 -1
  57. package/package.json +9 -5
  58. package/v1/extension-tests/conditional.json +289 -0
  59. package/v1/extension-tests/itemPattern.json +462 -0
  60. package/{stable → v1}/index.d.ts +2 -2
  61. package/{stable → v1}/index.js +25 -30
  62. package/{stable → v1}/meta/applicator.js +1 -3
  63. package/{stable → v1}/meta/content.js +1 -3
  64. package/{stable → v1}/meta/core.js +5 -4
  65. package/v1/meta/format.js +8 -0
  66. package/{stable → v1}/meta/meta-data.js +1 -3
  67. package/{stable → v1}/meta/unevaluated.js +1 -3
  68. package/{stable → v1}/meta/validation.js +1 -3
  69. package/v1/schema.js +24 -0
  70. package/stable/meta/format-annotation.js +0 -10
  71. package/stable/meta/format-assertion.js +0 -10
  72. package/stable/validation.js +0 -24
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@hyperjump/json-schema",
3
- "version": "1.16.4",
3
+ "version": "1.17.0",
4
4
  "description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
5
5
  "type": "module",
6
- "main": "./stable/index.js",
6
+ "main": "./v1/index.js",
7
7
  "exports": {
8
- ".": "./stable/index.js",
8
+ ".": "./v1/index.js",
9
9
  "./draft-04": "./draft-04/index.js",
10
10
  "./draft-06": "./draft-06/index.js",
11
11
  "./draft-07": "./draft-07/index.js",
@@ -13,15 +13,18 @@
13
13
  "./draft-2020-12": "./draft-2020-12/index.js",
14
14
  "./openapi-3-0": "./openapi-3-0/index.js",
15
15
  "./openapi-3-1": "./openapi-3-1/index.js",
16
+ "./openapi-3-2": "./openapi-3-2/index.js",
16
17
  "./experimental": "./lib/experimental.js",
17
18
  "./instance/experimental": "./lib/instance.js",
18
19
  "./annotations/experimental": "./annotations/index.js",
19
20
  "./annotated-instance/experimental": "./annotations/annotated-instance.js",
20
- "./bundle": "./bundle/index.js"
21
+ "./bundle": "./bundle/index.js",
22
+ "./formats": "./formats/index.js",
23
+ "./formats-lite": "./formats/lite.js"
21
24
  },
22
25
  "scripts": {
23
26
  "clean": "xargs -a .gitignore rm -rf",
24
- "lint": "eslint lib stable draft-* openapi-* bundle annotations",
27
+ "lint": "eslint lib v1 draft-* openapi-* bundle annotations",
25
28
  "test": "vitest --watch=false",
26
29
  "check-types": "tsc --noEmit"
27
30
  },
@@ -66,6 +69,7 @@
66
69
  },
67
70
  "dependencies": {
68
71
  "@hyperjump/json-pointer": "^1.1.0",
72
+ "@hyperjump/json-schema-formats": "^1.0.0",
69
73
  "@hyperjump/pact": "^1.2.0",
70
74
  "@hyperjump/uri": "^1.2.0",
71
75
  "content-type": "^1.0.4",
@@ -0,0 +1,289 @@
1
+ [
2
+ {
3
+ "description": "if - then",
4
+ "schema": {
5
+ "conditional": [
6
+ { "type": "string" },
7
+ { "maxLength": 5 }
8
+ ]
9
+ },
10
+ "tests": [
11
+ {
12
+ "description": "if passes, then passes",
13
+ "data": "foo",
14
+ "valid": true
15
+ },
16
+ {
17
+ "description": "if passes, then fails",
18
+ "data": "foobar",
19
+ "valid": false
20
+ },
21
+ {
22
+ "description": "if fails",
23
+ "data": 42,
24
+ "valid": true
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "description": "if - then - else",
30
+ "schema": {
31
+ "conditional": [
32
+ { "type": "string" },
33
+ { "maxLength": 5 },
34
+ { "type": "number" }
35
+ ]
36
+ },
37
+ "tests": [
38
+ {
39
+ "description": "if passes, then passes",
40
+ "data": "foo",
41
+ "valid": true
42
+ },
43
+ {
44
+ "description": "if passes, then fails",
45
+ "data": "foobar",
46
+ "valid": false
47
+ },
48
+ {
49
+ "description": "if fails, else passes",
50
+ "data": 42,
51
+ "valid": true
52
+ },
53
+ {
54
+ "description": "if fails, else fails",
55
+ "data": true,
56
+ "valid": false
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "description": "if - then - elseif - then",
62
+ "schema": {
63
+ "conditional": [
64
+ { "type": "string" },
65
+ { "maxLength": 5 },
66
+ { "type": "number" },
67
+ { "maximum": 50 }
68
+ ]
69
+ },
70
+ "tests": [
71
+ {
72
+ "description": "if passes, then passes",
73
+ "data": "foo",
74
+ "valid": true
75
+ },
76
+ {
77
+ "description": "if passes, then fails",
78
+ "data": "foobar",
79
+ "valid": false
80
+ },
81
+ {
82
+ "description": "if fails, elseif passes, then passes",
83
+ "data": 42,
84
+ "valid": true
85
+ },
86
+ {
87
+ "description": "if fails, elseif passes, then fails",
88
+ "data": 100,
89
+ "valid": false
90
+ },
91
+ {
92
+ "description": "if fails, elseif fails",
93
+ "data": true,
94
+ "valid": true
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "description": "if - then - elseif - then - else",
100
+ "schema": {
101
+ "conditional": [
102
+ { "type": "string" },
103
+ { "maxLength": 5 },
104
+ { "type": "number" },
105
+ { "maximum": 50 },
106
+ { "const": true }
107
+ ]
108
+ },
109
+ "tests": [
110
+ {
111
+ "description": "if passes, then passes",
112
+ "data": "foo",
113
+ "valid": true
114
+ },
115
+ {
116
+ "description": "if passes, then fails",
117
+ "data": "foobar",
118
+ "valid": false
119
+ },
120
+ {
121
+ "description": "if fails, elseif passes, then passes",
122
+ "data": 42,
123
+ "valid": true
124
+ },
125
+ {
126
+ "description": "if fails, elseif passes, then fails",
127
+ "data": 100,
128
+ "valid": false
129
+ },
130
+ {
131
+ "description": "if fails, elseif fails, else passes",
132
+ "data": true,
133
+ "valid": true
134
+ },
135
+ {
136
+ "description": "if fails, elseif fails, else fails",
137
+ "data": false,
138
+ "valid": false
139
+ }
140
+ ]
141
+ },
142
+ {
143
+ "description": "nested if - then - elseif - then - else",
144
+ "schema": {
145
+ "conditional": [
146
+ [
147
+ { "type": "string" },
148
+ { "maxLength": 5 }
149
+ ],
150
+ [
151
+ { "type": "number" },
152
+ { "maximum": 50 }
153
+ ],
154
+ { "const": true }
155
+ ]
156
+ },
157
+ "tests": [
158
+ {
159
+ "description": "if passes, then passes",
160
+ "data": "foo",
161
+ "valid": true
162
+ },
163
+ {
164
+ "description": "if passes, then fails",
165
+ "data": "foobar",
166
+ "valid": false
167
+ },
168
+ {
169
+ "description": "if fails, elseif passes, then passes",
170
+ "data": 42,
171
+ "valid": true
172
+ },
173
+ {
174
+ "description": "if fails, elseif passes, then fails",
175
+ "data": 100,
176
+ "valid": false
177
+ },
178
+ {
179
+ "description": "if fails, elseif fails, else passes",
180
+ "data": true,
181
+ "valid": true
182
+ },
183
+ {
184
+ "description": "if fails, elseif fails, else fails",
185
+ "data": false,
186
+ "valid": false
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ "description": "if - then - else with unevaluatedProperties",
192
+ "schema": {
193
+ "allOf": [
194
+ {
195
+ "properties": {
196
+ "foo": {}
197
+ },
198
+ "conditional": [
199
+ { "required": ["foo"] },
200
+ {
201
+ "properties": {
202
+ "bar": {}
203
+ }
204
+ },
205
+ {
206
+ "properties": {
207
+ "baz": {}
208
+ }
209
+ }
210
+ ]
211
+ }
212
+ ],
213
+ "unevaluatedProperties": false
214
+ },
215
+ "tests": [
216
+ {
217
+ "description": "if foo, then bar is allowed",
218
+ "data": { "foo": 42, "bar": true },
219
+ "valid": true
220
+ },
221
+ {
222
+ "description": "if foo, then baz is not allowed",
223
+ "data": { "foo": 42, "baz": true },
224
+ "valid": false
225
+ },
226
+ {
227
+ "description": "if not foo, then baz is allowed",
228
+ "data": { "baz": true },
229
+ "valid": true
230
+ },
231
+ {
232
+ "description": "if not foo, then bar is not allowed",
233
+ "data": { "bar": true },
234
+ "valid": false
235
+ }
236
+ ]
237
+ },
238
+ {
239
+ "description": "if - then - else with unevaluatedItems",
240
+ "schema": {
241
+ "allOf": [
242
+ {
243
+ "conditional": [
244
+ { "prefixItems": [{ "const": "foo" }] },
245
+ {
246
+ "prefixItems": [{}, { "const": "bar" }]
247
+ },
248
+ {
249
+ "prefixItems": [{}, { "const": "baz" }]
250
+ }
251
+ ]
252
+ }
253
+ ],
254
+ "unevaluatedItems": false
255
+ },
256
+ "tests": [
257
+ {
258
+ "description": "foo, bar",
259
+ "data": ["foo", "bar"],
260
+ "valid": true
261
+ },
262
+ {
263
+ "description": "foo, baz",
264
+ "data": ["foo", "baz"],
265
+ "valid": false
266
+ },
267
+ {
268
+ "description": "foo, bar, additional",
269
+ "data": ["foo", "bar", ""],
270
+ "valid": false
271
+ },
272
+ {
273
+ "description": "not-foo, baz",
274
+ "data": ["not-foo", "baz"],
275
+ "valid": true
276
+ },
277
+ {
278
+ "description": "not-foo, bar",
279
+ "data": ["not-foo", "bar"],
280
+ "valid": false
281
+ },
282
+ {
283
+ "description": "not-foo, baz, additional",
284
+ "data": ["not-foo", "baz", ""],
285
+ "valid": false
286
+ }
287
+ ]
288
+ }
289
+ ]