@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
@@ -70,6 +70,7 @@ export type OasSchema32 = boolean | {
70
70
  type Discriminator = {
71
71
  propertyName: string;
72
72
  mappings?: Record<string, string>;
73
+ defaultMapping?: string;
73
74
  };
74
75
 
75
76
  type ExternalDocs = {
@@ -78,6 +79,7 @@ type ExternalDocs = {
78
79
  };
79
80
 
80
81
  type Xml = {
82
+ nodeType?: "element" | "attribute" | "text" | "cdata" | "none";
81
83
  name?: string;
82
84
  namespace?: string;
83
85
  prefix?: string;
@@ -85,7 +87,329 @@ type Xml = {
85
87
  wrapped?: boolean;
86
88
  };
87
89
 
88
- // TODO: Fill in this type when 3.2 is published
89
- export type OpenApi32 = unknown;
90
+ export type OpenApi = {
91
+ openapi: string;
92
+ $self?: string;
93
+ info: Info;
94
+ jsonSchemaDialect?: string;
95
+ servers?: Server[];
96
+ paths?: Record<string, PathItem>;
97
+ webhooks?: Record<string, PathItem>;
98
+ components?: Components;
99
+ security?: SecurityRequirement[];
100
+ tags?: Tag[];
101
+ externalDocs?: ExternalDocs;
102
+ };
103
+
104
+ type Info = {
105
+ title: string;
106
+ summary?: string;
107
+ description?: string;
108
+ termsOfService?: string;
109
+ contact?: Contact;
110
+ license?: License;
111
+ version: string;
112
+ };
113
+
114
+ type Contact = {
115
+ name?: string;
116
+ url?: string;
117
+ email?: string;
118
+ };
119
+
120
+ type License = {
121
+ name: string;
122
+ identifier?: string;
123
+ url?: string;
124
+ };
125
+
126
+ type Server = {
127
+ url: string;
128
+ description?: string;
129
+ name?: string;
130
+ variables?: Record<string, ServerVariable>;
131
+ };
132
+
133
+ type ServerVariable = {
134
+ enum?: string[];
135
+ default: string;
136
+ description?: string;
137
+ };
138
+
139
+ type Components = {
140
+ schemas?: Record<string, OasSchema32>;
141
+ responses?: Record<string, Response | Reference>;
142
+ parameters?: Record<string, Parameter | Reference>;
143
+ examples?: Record<string, Example | Reference>;
144
+ requestBodies?: Record<string, RequestBody | Reference>;
145
+ headers?: Record<string, Header | Reference>;
146
+ securitySchemes?: Record<string, SecurityScheme | Reference>;
147
+ links?: Record<string, Link | Reference>;
148
+ callbacks?: Record<string, Callbacks | Reference>;
149
+ pathItems?: Record<string, PathItem>;
150
+ mediaTypes?: Record<string, MediaType | Reference>;
151
+ };
152
+
153
+ type PathItem = {
154
+ $ref?: string;
155
+ summary?: string;
156
+ description?: string;
157
+ get?: Operation;
158
+ put?: Operation;
159
+ post?: Operation;
160
+ delete?: Operation;
161
+ options?: Operation;
162
+ head?: Operation;
163
+ patch?: Operation;
164
+ trace?: Operation;
165
+ query?: Operation;
166
+ additionOperations?: Record<string, Operation>;
167
+ servers?: Server[];
168
+ parameters?: (Parameter | Reference)[];
169
+ };
170
+
171
+ type Operation = {
172
+ tags?: string[];
173
+ summary?: string;
174
+ description?: string;
175
+ externalDocs?: ExternalDocs;
176
+ operationId?: string;
177
+ parameters?: (Parameter | Reference)[];
178
+ requestBody?: RequestBody | Reference;
179
+ responses?: Responses;
180
+ callbacks?: Record<string, Callbacks | Reference>;
181
+ deprecated?: boolean;
182
+ security?: SecurityRequirement[];
183
+ servers?: Server[];
184
+ };
185
+
186
+ export type Parameter = {
187
+ name: string;
188
+ description?: string;
189
+ required?: boolean;
190
+ deprecated?: boolean;
191
+ allowEmptyValue?: boolean;
192
+ } & Examples & (
193
+ (
194
+ {
195
+ in: "path";
196
+ required: true;
197
+ } & (
198
+ ({ style?: "matrix" | "label" | "simple" } & SchemaParameter)
199
+ | ContentParameter
200
+ )
201
+ ) | (
202
+ {
203
+ in: "query";
204
+ } & (
205
+ ({ style?: "form" | "spaceDelimited" | "pipeDelimited" | "deepObject" } & SchemaParameter)
206
+ | ContentParameter
207
+ )
208
+ ) | (
209
+ {
210
+ in: "header";
211
+ } & (
212
+ ({ style?: "simple" } & SchemaParameter)
213
+ | ContentParameter
214
+ )
215
+ ) | (
216
+ {
217
+ in: "cookie";
218
+ } & (
219
+ ({ style?: "cookie" } & SchemaParameter)
220
+ | ContentParameter
221
+ )
222
+ ) | (
223
+ { in: "querystring" } & ContentParameter
224
+ )
225
+ );
226
+
227
+ type ContentParameter = {
228
+ schema?: never;
229
+ content: Record<string, MediaType | Reference>;
230
+ };
231
+
232
+ type SchemaParameter = {
233
+ explode?: boolean;
234
+ allowReserved?: boolean;
235
+ schema: OasSchema32;
236
+ content?: never;
237
+ };
238
+
239
+ type RequestBody = {
240
+ description?: string;
241
+ content: Record<string, MediaType | Reference>;
242
+ required?: boolean;
243
+ };
244
+
245
+ type MediaType = {
246
+ schema?: OasSchema32;
247
+ itemSchema?: OasSchema32;
248
+ } & Examples & ({
249
+ encoding?: Record<string, Encoding>;
250
+ prefixEncoding?: never;
251
+ itemEncoding?: never;
252
+ } | {
253
+ encoding?: never;
254
+ prefixEncoding?: Encoding[];
255
+ itemEncoding?: Encoding;
256
+ });
257
+
258
+ type Encoding = {
259
+ contentType?: string;
260
+ headers?: Record<string, Header | Reference>;
261
+ style?: "form" | "spaceDelimited" | "pipeDelimited" | "deepObject";
262
+ explode?: boolean;
263
+ allowReserved?: boolean;
264
+ } & ({
265
+ encoding?: Record<string, Encoding>;
266
+ prefixEncoding?: never;
267
+ itemEncoding?: never;
268
+ } | {
269
+ encoding?: never;
270
+ prefixEncoding?: Encoding[];
271
+ itemEncoding?: Encoding;
272
+ });
273
+
274
+ type Responses = {
275
+ default?: Response | Reference;
276
+ } & Record<string, Response | Reference>;
277
+
278
+ type Response = {
279
+ summary?: string;
280
+ description?: string;
281
+ headers?: Record<string, Header | Reference>;
282
+ content?: Record<string, MediaType | Reference>;
283
+ links?: Record<string, Link | Reference>;
284
+ };
285
+
286
+ type Callbacks = Record<string, PathItem | Reference>;
287
+
288
+ type Examples = {
289
+ example?: Json;
290
+ examples?: Record<string, Example | Reference>;
291
+ };
292
+
293
+ type Example = {
294
+ summary?: string;
295
+ description?: string;
296
+ } & ({
297
+ value?: Json;
298
+ dataValue?: never;
299
+ serializedValue?: never;
300
+ externalValue?: never;
301
+ } | {
302
+ value?: never;
303
+ dataValue?: Json;
304
+ serializedValue?: string;
305
+ externalValue?: string;
306
+ });
307
+
308
+ type Link = {
309
+ operationRef?: string;
310
+ operationId?: string;
311
+ parameters?: Record<string, string>;
312
+ requestBody?: Json;
313
+ description?: string;
314
+ server?: Server;
315
+ };
316
+
317
+ type Header = {
318
+ description?: string;
319
+ required?: boolean;
320
+ deprecated?: boolean;
321
+ } & Examples & ({
322
+ style?: "simple";
323
+ explode?: boolean;
324
+ schema: OasSchema32;
325
+ } | {
326
+ content: Record<string, MediaType | Reference>;
327
+ });
328
+
329
+ type Tag = {
330
+ name: string;
331
+ summary?: string;
332
+ description?: string;
333
+ externalDocs?: ExternalDocs;
334
+ parent?: string;
335
+ kind?: string;
336
+ };
337
+
338
+ type Reference = {
339
+ $ref: string;
340
+ summary?: string;
341
+ description?: string;
342
+ };
343
+
344
+ type SecurityScheme = {
345
+ type: "apiKey";
346
+ description?: string;
347
+ name: string;
348
+ in: "query" | "header" | "cookie";
349
+ deprecated?: boolean;
350
+ } | {
351
+ type: "http";
352
+ description?: string;
353
+ scheme: string;
354
+ bearerFormat?: string;
355
+ deprecated?: boolean;
356
+ } | {
357
+ type: "mutualTLS";
358
+ description?: string;
359
+ deprecated?: boolean;
360
+ } | {
361
+ type: "oauth2";
362
+ description?: string;
363
+ flows: OauthFlows;
364
+ oauth2MetadataUrl?: string;
365
+ deprecated?: boolean;
366
+ } | {
367
+ type: "openIdConnect";
368
+ description?: string;
369
+ openIdConnectUrl: string;
370
+ deprecated?: boolean;
371
+ };
372
+
373
+ type OauthFlows = {
374
+ implicit?: Implicit;
375
+ password?: Password;
376
+ clientCredentials?: ClientCredentials;
377
+ authorizationCode?: AuthorizationCode;
378
+ deviceAuthorization?: DeviceAuthorization;
379
+ };
380
+
381
+ type Implicit = {
382
+ authorizationUrl: string;
383
+ refreshUrl?: string;
384
+ scopes: Record<string, string>;
385
+ };
386
+
387
+ type Password = {
388
+ tokenUrl: string;
389
+ refreshUrl?: string;
390
+ scopes: Record<string, string>;
391
+ };
392
+
393
+ type ClientCredentials = {
394
+ tokenUrl: string;
395
+ refreshUrl?: string;
396
+ scopes: Record<string, string>;
397
+ };
398
+
399
+ type AuthorizationCode = {
400
+ authorizationUrl: string;
401
+ tokenUrl: string;
402
+ refreshUrl?: string;
403
+ scopes: Record<string, string>;
404
+ };
405
+
406
+ type DeviceAuthorization = {
407
+ deviceAuthorizationUrl: string;
408
+ tokenUrl: string;
409
+ refreshUrl?: string;
410
+ scopes: Record<string, string>;
411
+ };
412
+
413
+ type SecurityRequirement = Record<string, string[]>;
90
414
 
91
415
  export * from "../lib/index.js";
@@ -32,14 +32,12 @@ defineVocabulary("https://spec.openapis.org/oas/3.2/vocab/base", {
32
32
  "xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
33
33
  });
34
34
 
35
- registerSchema(vocabularySchema, "https://spec.openapis.org/oas/3.2/meta/base");
36
- registerSchema(dialectSchema, "https://spec.openapis.org/oas/3.2/dialect/base");
35
+ registerSchema(vocabularySchema, "https://spec.openapis.org/oas/3.2/meta");
36
+ registerSchema(dialectSchema, "https://spec.openapis.org/oas/3.2/dialect");
37
37
 
38
38
  // Current Schemas
39
39
  registerSchema(schema, "https://spec.openapis.org/oas/3.2/schema");
40
- registerSchema(schema, "https://spec.openapis.org/oas/3.2/schema/latest");
41
40
  registerSchema(schemaBase, "https://spec.openapis.org/oas/3.2/schema-base");
42
- registerSchema(schemaBase, "https://spec.openapis.org/oas/3.2/schema-base/latest");
43
41
 
44
42
  // Alternative dialect schemas
45
43
  registerSchema(schemaDraft2020, "https://spec.openapis.org/oas/3.2/schema-draft-2020-12");
@@ -3,21 +3,23 @@ export default {
3
3
  "$dynamicAnchor": "meta",
4
4
 
5
5
  "title": "OAS Base Vocabulary",
6
- "description": "A JSON Schema Vocabulary used in the OpenAPI Schema Dialect",
6
+ "description": "A JSON Schema Vocabulary used in the OpenAPI JSON Schema Dialect",
7
7
 
8
8
  "type": ["object", "boolean"],
9
9
  "properties": {
10
- "example": true,
11
10
  "discriminator": { "$ref": "#/$defs/discriminator" },
11
+ "example": { "deprecated": true },
12
12
  "externalDocs": { "$ref": "#/$defs/external-docs" },
13
13
  "xml": { "$ref": "#/$defs/xml" }
14
14
  },
15
+
15
16
  "$defs": {
16
17
  "extensible": {
17
18
  "patternProperties": {
18
19
  "^x-": true
19
20
  }
20
21
  },
22
+
21
23
  "discriminator": {
22
24
  "$ref": "#/$defs/extensible",
23
25
  "type": "object",
@@ -30,6 +32,9 @@ export default {
30
32
  "additionalProperties": {
31
33
  "type": "string"
32
34
  }
35
+ },
36
+ "defaultMapping": {
37
+ "type": "string"
33
38
  }
34
39
  },
35
40
  "required": ["propertyName"],
@@ -54,21 +59,41 @@ export default {
54
59
  "$ref": "#/$defs/extensible",
55
60
  "type": "object",
56
61
  "properties": {
62
+ "nodeType": {
63
+ "type": "string",
64
+ "enum": [
65
+ "element",
66
+ "attribute",
67
+ "text",
68
+ "cdata",
69
+ "none"
70
+ ]
71
+ },
57
72
  "name": {
58
73
  "type": "string"
59
74
  },
60
75
  "namespace": {
61
76
  "type": "string",
62
- "format": "uri"
77
+ "format": "iri"
63
78
  },
64
79
  "prefix": {
65
80
  "type": "string"
66
81
  },
67
82
  "attribute": {
68
- "type": "boolean"
83
+ "type": "boolean",
84
+ "deprecated": true
69
85
  },
70
86
  "wrapped": {
71
- "type": "boolean"
87
+ "type": "boolean",
88
+ "deprecated": true
89
+ }
90
+ },
91
+ "dependentSchemas": {
92
+ "nodeType": {
93
+ "properties": {
94
+ "attribute": false,
95
+ "wrapped": false
96
+ }
72
97
  }
73
98
  },
74
99
  "unevaluatedProperties": false
@@ -20,11 +20,10 @@ export default {
20
20
  },
21
21
 
22
22
  "$defs": {
23
- "dialect": { "const": "https://spec.openapis.org/oas/3.2/dialect/base" },
24
-
23
+ "dialect": { "const": "https://spec.openapis.org/oas/3.2/dialect" },
25
24
  "schema": {
26
25
  "$dynamicAnchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
26
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
27
  "properties": {
29
28
  "$schema": { "$ref": "#/$defs/dialect" }
30
29
  }
@@ -12,7 +12,7 @@ export default {
12
12
  "https://spec.openapis.org/oas/3.2/vocab/base": false
13
13
  },
14
14
 
15
- "description": "OpenAPI v3.2.x documents using draft-04 JSON Schemas",
15
+ "description": "The description of OpenAPI v3.2.x Documents using the draft-04 JSON Schema dialect",
16
16
 
17
17
  "$ref": "https://spec.openapis.org/oas/3.2/schema",
18
18
  "properties": {
@@ -24,7 +24,7 @@ export default {
24
24
 
25
25
  "schema": {
26
26
  "$dynamicAnchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
27
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
28
  "properties": {
29
29
  "$schema": { "$ref": "#/$defs/dialect" }
30
30
  }
@@ -12,7 +12,7 @@ export default {
12
12
  "https://spec.openapis.org/oas/3.2/vocab/base": false
13
13
  },
14
14
 
15
- "description": "OpenAPI v3.2.x documents using draft-06 JSON Schemas",
15
+ "description": "The description of OpenAPI v3.2.x Documents using the draft-06 JSON Schema dialect",
16
16
 
17
17
  "$ref": "https://spec.openapis.org/oas/3.2/schema",
18
18
  "properties": {
@@ -24,7 +24,7 @@ export default {
24
24
 
25
25
  "schema": {
26
26
  "$dynamicAnchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
27
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
28
  "properties": {
29
29
  "$schema": { "$ref": "#/$defs/dialect" }
30
30
  }
@@ -12,7 +12,7 @@ export default {
12
12
  "https://spec.openapis.org/oas/3.2/vocab/base": false
13
13
  },
14
14
 
15
- "description": "OpenAPI v3.2.x documents using draft-07 JSON Schemas",
15
+ "description": "The description of OpenAPI v3.2.x Documents using the draft-07 JSON Schema dialect",
16
16
 
17
17
  "$ref": "https://spec.openapis.org/oas/3.2/schema",
18
18
  "properties": {
@@ -24,7 +24,7 @@ export default {
24
24
 
25
25
  "schema": {
26
26
  "$dynamicAnchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
27
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
28
  "properties": {
29
29
  "$schema": { "$ref": "#/$defs/dialect" }
30
30
  }
@@ -12,7 +12,7 @@ export default {
12
12
  "https://spec.openapis.org/oas/3.2/vocab/base": false
13
13
  },
14
14
 
15
- "description": "openapi v3.2.x documents using 2019-09 json schemas",
15
+ "description": "The description of OpenAPI v3.2.x Documents using the 2019-09 JSON Schema dialect",
16
16
 
17
17
  "$ref": "https://spec.openapis.org/oas/3.2/schema",
18
18
  "properties": {
@@ -23,8 +23,8 @@ export default {
23
23
  "dialect": { "const": "https://json-schema.org/draft/2019-09/schema" },
24
24
 
25
25
  "schema": {
26
- "$dynamicanchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
26
+ "$dynamicAnchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
28
  "properties": {
29
29
  "$schema": { "$ref": "#/$defs/dialect" }
30
30
  }
@@ -12,7 +12,7 @@ export default {
12
12
  "https://spec.openapis.org/oas/3.2/vocab/base": false
13
13
  },
14
14
 
15
- "description": "openapi v3.2.x documents using 2020-12 json schemas",
15
+ "description": "The description of OpenAPI v3.2.x Documents using the 2020-12 JSON Schema dialect",
16
16
 
17
17
  "$ref": "https://spec.openapis.org/oas/3.2/schema",
18
18
  "properties": {
@@ -23,8 +23,8 @@ export default {
23
23
  "dialect": { "const": "https://json-schema.org/draft/2020-12/schema" },
24
24
 
25
25
  "schema": {
26
- "$dynamicanchor": "meta",
27
- "$ref": "https://spec.openapis.org/oas/3.2/dialect/base",
26
+ "$dynamicAnchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.2/dialect",
28
28
  "properties": {
29
29
  "$schema": { "$ref": "#/$defs/dialect" }
30
30
  }