z-schema 9.0.1 → 10.0.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 (59) hide show
  1. package/README.md +123 -191
  2. package/cjs/index.d.ts +33 -9
  3. package/cjs/index.js +4799 -3984
  4. package/dist/errors.js +5 -0
  5. package/dist/format-validators.js +65 -0
  6. package/dist/json-schema-versions.js +5 -0
  7. package/dist/json-schema.js +11 -4
  8. package/dist/json-validation.js +151 -10
  9. package/dist/report.js +2 -3
  10. package/dist/schema-cache.js +23 -2
  11. package/dist/schema-compiler.js +25 -10
  12. package/dist/schema-validator.js +66 -45
  13. package/dist/schemas/draft-06-hyper-schema.json +132 -0
  14. package/dist/schemas/draft-06-links.json +43 -0
  15. package/dist/schemas/draft-06-schema.json +155 -0
  16. package/dist/types/errors.d.ts +4 -0
  17. package/dist/types/index.d.ts +2 -1
  18. package/dist/types/json-schema-versions.d.ts +23 -0
  19. package/dist/types/json-schema.d.ts +5 -9
  20. package/dist/types/json-validation.d.ts +3 -3
  21. package/dist/types/report.d.ts +3 -3
  22. package/dist/types/schema-cache.d.ts +1 -1
  23. package/dist/types/schema-compiler.d.ts +1 -1
  24. package/dist/types/schema-validator.d.ts +1 -1
  25. package/dist/types/utils/what-is.d.ts +1 -0
  26. package/dist/types/z-schema-base.d.ts +1 -1
  27. package/dist/types/z-schema-options.d.ts +1 -1
  28. package/dist/types/z-schema-reader.d.ts +1 -1
  29. package/dist/types/z-schema-versions.d.ts +1 -0
  30. package/dist/types/z-schema.d.ts +10 -1
  31. package/dist/utils/schema-regex.js +4 -3
  32. package/dist/utils/what-is.js +4 -1
  33. package/dist/z-schema-base.js +4 -5
  34. package/dist/z-schema-options.js +3 -1
  35. package/dist/z-schema-versions.js +27 -0
  36. package/dist/z-schema.js +21 -7
  37. package/package.json +2 -2
  38. package/src/errors.ts +6 -0
  39. package/src/format-validators.ts +65 -0
  40. package/src/index.ts +2 -1
  41. package/src/json-schema-versions.ts +34 -0
  42. package/src/json-schema.ts +22 -16
  43. package/src/json-validation.ts +183 -13
  44. package/src/report.ts +5 -6
  45. package/src/schema-cache.ts +25 -3
  46. package/src/schema-compiler.ts +25 -11
  47. package/src/schema-validator.ts +128 -62
  48. package/src/schemas/draft-06-hyper-schema.json +133 -0
  49. package/src/schemas/draft-06-links.json +43 -0
  50. package/src/schemas/draft-06-schema.json +155 -0
  51. package/src/utils/schema-regex.ts +5 -3
  52. package/src/utils/what-is.ts +5 -1
  53. package/src/z-schema-base.ts +5 -6
  54. package/src/z-schema-options.ts +3 -2
  55. package/src/z-schema-reader.ts +1 -1
  56. package/src/z-schema-versions.ts +38 -0
  57. package/src/z-schema.ts +27 -11
  58. package/umd/ZSchema.js +5100 -4285
  59. package/umd/ZSchema.min.js +1 -1
@@ -1,10 +1,11 @@
1
1
  import { isFormatSupported } from './format-validators.js';
2
+ import { getId } from './json-schema.js';
2
3
  import { validate } from './json-validation.js';
3
4
  import { Report } from './report.js';
4
5
  import { isUniqueArray } from './utils/array.js';
5
6
  import { shallowClone } from './utils/clone.js';
6
7
  import { compileSchemaRegex } from './utils/schema-regex.js';
7
- import { isObject, whatIs } from './utils/what-is.js';
8
+ import { isInteger, isObject } from './utils/what-is.js';
8
9
  const SchemaValidators = {
9
10
  $ref: function (report, schema) {
10
11
  // http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07
@@ -36,11 +37,18 @@ const SchemaValidators = {
36
37
  },
37
38
  exclusiveMaximum: function (report, schema) {
38
39
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.2.1
39
- if (typeof schema.exclusiveMaximum !== 'boolean') {
40
- report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMaximum', 'boolean'], undefined, schema, 'exclusiveMaximum');
40
+ if (report.options.version === 'draft-04') {
41
+ if (typeof schema.exclusiveMaximum !== 'boolean') {
42
+ report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMaximum', 'boolean'], undefined, schema, 'exclusiveMaximum');
43
+ }
44
+ else if (schema.maximum === undefined) {
45
+ report.addError('KEYWORD_DEPENDENCY', ['exclusiveMaximum', 'maximum'], undefined, schema, 'exclusiveMaximum');
46
+ }
41
47
  }
42
- else if (schema.maximum === undefined) {
43
- report.addError('KEYWORD_DEPENDENCY', ['exclusiveMaximum', 'maximum'], undefined, schema, 'exclusiveMaximum');
48
+ else {
49
+ if (typeof schema.exclusiveMaximum !== 'boolean' && typeof schema.exclusiveMaximum !== 'number') {
50
+ report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMaximum', ['boolean', 'number']], undefined, schema, 'exclusiveMaximum');
51
+ }
44
52
  }
45
53
  },
46
54
  minimum: function (report, schema) {
@@ -50,17 +58,24 @@ const SchemaValidators = {
50
58
  }
51
59
  },
52
60
  exclusiveMinimum: function (report, schema) {
53
- // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.1
54
- if (typeof schema.exclusiveMinimum !== 'boolean') {
55
- report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMinimum', 'boolean'], undefined, schema, 'exclusiveMinimum');
61
+ if (report.options.version === 'draft-04') {
62
+ // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.1
63
+ if (typeof schema.exclusiveMinimum !== 'boolean') {
64
+ report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMinimum', 'boolean'], undefined, schema, 'exclusiveMinimum');
65
+ }
66
+ else if (schema.minimum === undefined) {
67
+ report.addError('KEYWORD_DEPENDENCY', ['exclusiveMinimum', 'minimum'], undefined, schema, 'exclusiveMinimum');
68
+ }
56
69
  }
57
- else if (schema.minimum === undefined) {
58
- report.addError('KEYWORD_DEPENDENCY', ['exclusiveMinimum', 'minimum'], undefined, schema, 'exclusiveMinimum');
70
+ else {
71
+ if (typeof schema.exclusiveMinimum !== 'boolean' && typeof schema.exclusiveMinimum !== 'number') {
72
+ report.addError('KEYWORD_TYPE_EXPECTED', ['exclusiveMinimum', ['boolean', 'number']], undefined, schema, 'exclusiveMinimum');
73
+ }
59
74
  }
60
75
  },
61
76
  maxLength: function (report, schema) {
62
77
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1.1
63
- if (whatIs(schema.maxLength) !== 'integer') {
78
+ if (!isInteger(schema.maxLength)) {
64
79
  report.addError('KEYWORD_TYPE_EXPECTED', ['maxLength', 'integer'], undefined, schema, 'maxLength');
65
80
  }
66
81
  else if (schema.maxLength < 0) {
@@ -69,7 +84,7 @@ const SchemaValidators = {
69
84
  },
70
85
  minLength: function (report, schema) {
71
86
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.2.1
72
- if (whatIs(schema.minLength) !== 'integer') {
87
+ if (!isInteger(schema.minLength)) {
73
88
  report.addError('KEYWORD_TYPE_EXPECTED', ['minLength', 'integer'], undefined, schema, 'minLength');
74
89
  }
75
90
  else if (schema.minLength < 0) {
@@ -92,8 +107,7 @@ const SchemaValidators = {
92
107
  },
93
108
  additionalItems: function (report, schema) {
94
109
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.1.1
95
- const type = whatIs(schema.additionalItems);
96
- if (type !== 'boolean' && type !== 'object') {
110
+ if (typeof schema.additionalItems !== 'boolean' && !isObject(schema.additionalItems)) {
97
111
  report.addError('KEYWORD_TYPE_EXPECTED', ['additionalItems', ['boolean', 'object']], undefined, schema, 'additionalItems');
98
112
  }
99
113
  else if (isObject(schema.additionalItems)) {
@@ -104,13 +118,7 @@ const SchemaValidators = {
104
118
  },
105
119
  items: function (report, schema) {
106
120
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.1.1
107
- const type = whatIs(schema.items);
108
- if (type === 'object') {
109
- report.path.push('items');
110
- this.validateSchema(report, schema.items);
111
- report.path.pop();
112
- }
113
- else if (Array.isArray(schema.items)) {
121
+ if (Array.isArray(schema.items)) {
114
122
  let idx = schema.items.length;
115
123
  while (idx--) {
116
124
  report.path.push('items');
@@ -120,8 +128,13 @@ const SchemaValidators = {
120
128
  report.path.pop();
121
129
  }
122
130
  }
131
+ else if (isObject(schema.items) || (report.options.version !== 'draft-04' && typeof schema.items === 'boolean')) {
132
+ report.path.push('items');
133
+ this.validateSchema(report, schema.items);
134
+ report.path.pop();
135
+ }
123
136
  else {
124
- report.addError('KEYWORD_TYPE_EXPECTED', ['items', ['array', 'object']], undefined, schema, 'items');
137
+ report.addError('KEYWORD_TYPE_EXPECTED', ['items', report.options.version === 'draft-04' ? ['array', 'object'] : ['array', 'object', 'boolean']], undefined, schema, 'items');
125
138
  }
126
139
  // custom - strict mode
127
140
  if (this.options.forceAdditional === true && schema.additionalItems === undefined && Array.isArray(schema.items)) {
@@ -143,7 +156,7 @@ const SchemaValidators = {
143
156
  },
144
157
  minItems: function (report, schema) {
145
158
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.3.3.1
146
- if (whatIs(schema.minItems) !== 'integer') {
159
+ if (!isInteger(schema.minItems)) {
147
160
  report.addError('KEYWORD_TYPE_EXPECTED', ['minItems', 'integer'], undefined, schema, 'minItems');
148
161
  }
149
162
  else if (schema.minItems < 0) {
@@ -158,7 +171,7 @@ const SchemaValidators = {
158
171
  },
159
172
  maxProperties: function (report, schema) {
160
173
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.1.1
161
- if (whatIs(schema.maxProperties) !== 'integer') {
174
+ if (!isInteger(schema.maxProperties)) {
162
175
  report.addError('KEYWORD_TYPE_EXPECTED', ['maxProperties', 'integer'], undefined, schema, 'maxProperties');
163
176
  }
164
177
  else if (schema.maxProperties < 0) {
@@ -167,7 +180,7 @@ const SchemaValidators = {
167
180
  },
168
181
  minProperties: function (report, schema) {
169
182
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.2.1
170
- if (whatIs(schema.minProperties) !== 'integer') {
183
+ if (!isInteger(schema.minProperties)) {
171
184
  report.addError('KEYWORD_TYPE_EXPECTED', ['minProperties', 'integer'], undefined, schema, 'minProperties');
172
185
  }
173
186
  else if (schema.minProperties < 0) {
@@ -176,10 +189,10 @@ const SchemaValidators = {
176
189
  },
177
190
  required: function (report, schema) {
178
191
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.3.1
179
- if (whatIs(schema.required) !== 'array') {
192
+ if (!Array.isArray(schema.required)) {
180
193
  report.addError('KEYWORD_TYPE_EXPECTED', ['required', 'array'], undefined, schema, 'required');
181
194
  }
182
- else if (schema.required.length === 0) {
195
+ else if (report.options.version === 'draft-04' && schema.required.length === 0) {
183
196
  report.addError('KEYWORD_MUST_BE', ['required', 'an array with at least one element'], undefined, schema, 'required');
184
197
  }
185
198
  else {
@@ -196,8 +209,7 @@ const SchemaValidators = {
196
209
  },
197
210
  additionalProperties: function (report, schema) {
198
211
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
199
- const type = whatIs(schema.additionalProperties);
200
- if (type !== 'boolean' && type !== 'object') {
212
+ if (typeof schema.additionalProperties !== 'boolean' && !isObject(schema.additionalProperties)) {
201
213
  report.addError('KEYWORD_TYPE_EXPECTED', ['additionalProperties', ['boolean', 'object']], undefined, schema, 'additionalProperties');
202
214
  }
203
215
  else if (isObject(schema.additionalProperties)) {
@@ -208,7 +220,7 @@ const SchemaValidators = {
208
220
  },
209
221
  properties: function (report, schema) {
210
222
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
211
- if (whatIs(schema.properties) !== 'object') {
223
+ if (!isObject(schema.properties)) {
212
224
  report.addError('KEYWORD_TYPE_EXPECTED', ['properties', 'object'], undefined, schema, 'properties');
213
225
  return;
214
226
  }
@@ -238,7 +250,7 @@ const SchemaValidators = {
238
250
  },
239
251
  patternProperties: function (report, schema) {
240
252
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.1
241
- if (whatIs(schema.patternProperties) !== 'object') {
253
+ if (!isObject(schema.patternProperties)) {
242
254
  report.addError('KEYWORD_TYPE_EXPECTED', ['patternProperties', 'object'], undefined, schema, 'patternProperties');
243
255
  return;
244
256
  }
@@ -264,7 +276,7 @@ const SchemaValidators = {
264
276
  },
265
277
  dependencies: function (report, schema) {
266
278
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.5.1
267
- if (whatIs(schema.dependencies) !== 'object') {
279
+ if (!isObject(schema.dependencies)) {
268
280
  report.addError('KEYWORD_TYPE_EXPECTED', ['dependencies', 'object'], undefined, schema, 'dependencies');
269
281
  }
270
282
  else {
@@ -273,30 +285,32 @@ const SchemaValidators = {
273
285
  while (idx--) {
274
286
  const schemaKey = keys[idx];
275
287
  const schemaDependency = schema.dependencies[schemaKey];
276
- const type = whatIs(schemaDependency);
277
- if (type === 'object') {
288
+ const isSchemaDependency = isObject(schemaDependency) ||
289
+ (report.options.version !== 'draft-04' && typeof schemaDependency === 'boolean');
290
+ if (isSchemaDependency) {
278
291
  report.path.push('dependencies');
279
292
  report.path.push(schemaKey);
280
293
  this.validateSchema(report, schemaDependency);
281
294
  report.path.pop();
282
295
  report.path.pop();
283
296
  }
284
- else if (type === 'array') {
285
- let idx2 = schemaDependency.length;
286
- if (idx2 === 0) {
297
+ else if (Array.isArray(schemaDependency)) {
298
+ const depArray = schemaDependency;
299
+ let idx2 = depArray.length;
300
+ if (report.options.version === 'draft-04' && idx2 === 0) {
287
301
  report.addError('KEYWORD_MUST_BE', ['dependencies', 'not empty array'], undefined, schema, 'dependencies');
288
302
  }
289
303
  while (idx2--) {
290
- if (typeof schemaDependency[idx2] !== 'string') {
304
+ if (typeof depArray[idx2] !== 'string') {
291
305
  report.addError('KEYWORD_VALUE_TYPE', ['dependencies', 'string'], undefined, schema, 'dependencies');
292
306
  }
293
307
  }
294
- if (isUniqueArray(schemaDependency) === false) {
308
+ if (isUniqueArray(depArray) === false) {
295
309
  report.addError('KEYWORD_MUST_BE', ['dependencies', 'an array with unique items'], undefined, schema, 'dependencies');
296
310
  }
297
311
  }
298
312
  else {
299
- report.addError('KEYWORD_VALUE_TYPE', ['dependencies', 'object or array'], undefined, schema, 'dependencies');
313
+ report.addError('KEYWORD_VALUE_TYPE', ['dependencies', report.options.version === 'draft-04' ? 'object or array' : 'boolean, object or array'], undefined, schema, 'dependencies');
300
314
  }
301
315
  }
302
316
  }
@@ -459,18 +473,22 @@ const SchemaValidators = {
459
473
  },
460
474
  not: function (report, schema) {
461
475
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.6.1
462
- if (whatIs(schema.not) !== 'object') {
463
- report.addError('KEYWORD_TYPE_EXPECTED', ['not', 'object'], undefined, schema, 'not');
476
+ const notSchema = schema.not;
477
+ const isValidNotSchema = report.options.version === 'draft-04'
478
+ ? isObject(notSchema)
479
+ : typeof notSchema === 'boolean' || isObject(notSchema);
480
+ if (!isValidNotSchema) {
481
+ report.addError('KEYWORD_TYPE_EXPECTED', ['not', report.options.version === 'draft-04' ? 'object' : ['boolean', 'object']], undefined, schema, 'not');
464
482
  }
465
483
  else {
466
484
  report.path.push('not');
467
- this.validateSchema(report, schema.not);
485
+ this.validateSchema(report, notSchema);
468
486
  report.path.pop();
469
487
  }
470
488
  },
471
489
  definitions: function (report, schema) {
472
490
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.7.1
473
- if (whatIs(schema.definitions) !== 'object') {
491
+ if (!isObject(schema.definitions)) {
474
492
  report.addError('KEYWORD_TYPE_EXPECTED', ['definitions', 'object'], undefined, schema, 'definitions');
475
493
  }
476
494
  else {
@@ -540,12 +558,15 @@ export class SchemaValidator {
540
558
  if (Array.isArray(schema)) {
541
559
  return this.validateArrayOfSchemas(report, schema);
542
560
  }
561
+ if (typeof schema === 'boolean') {
562
+ return true;
563
+ }
543
564
  // do not revalidate schema that has already been validated once
544
565
  if (schema.__$validated) {
545
566
  return true;
546
567
  }
547
568
  // if $schema is present, this schema should validate against that $schema
548
- const hasParentSchema = schema.$schema && schema.id !== schema.$schema;
569
+ const hasParentSchema = schema.$schema && getId(schema) !== schema.$schema;
549
570
  if (hasParentSchema) {
550
571
  if (schema.__$schemaResolved && schema.__$schemaResolved !== schema) {
551
572
  const subReport = new Report(report);
@@ -0,0 +1,132 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/hyper-schema#",
3
+ "$id": "http://json-schema.org/draft-06/hyper-schema#",
4
+ "title": "JSON Hyper-Schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "allOf": [
8
+ { "$ref": "http://json-schema.org/draft-06/schema#/definitions/schemaArray" },
9
+ {
10
+ "items": { "$ref": "#" }
11
+ }
12
+ ]
13
+ },
14
+ "linkDescription": {
15
+ "title": "Link Description Object",
16
+ "type": "object",
17
+ "required": ["href"],
18
+ "properties": {
19
+ "href": {
20
+ "description": "a URI template, as defined by RFC 6570",
21
+ "type": "string",
22
+ "format": "uri-template"
23
+ },
24
+ "hrefSchema": {
25
+ "description": "a schema for validating user input to the URI template, where the input is in the form of a JSON object with property names matching variable names in \"href\"",
26
+ "allOf": [{ "$ref": "#" }]
27
+ },
28
+ "rel": {
29
+ "description": "relation to the target resource of the link",
30
+ "type": "string"
31
+ },
32
+ "title": {
33
+ "description": "a title for the link",
34
+ "type": "string"
35
+ },
36
+ "targetSchema": {
37
+ "description": "JSON Schema describing the link target",
38
+ "allOf": [{ "$ref": "#" }]
39
+ },
40
+ "mediaType": {
41
+ "description": "media type (as defined by RFC 2046) describing the link target",
42
+ "type": "string"
43
+ },
44
+ "submissionEncType": {
45
+ "description": "The media type in which to submit data along with the request",
46
+ "type": "string",
47
+ "default": "application/json"
48
+ },
49
+ "submissionSchema": {
50
+ "description": "Schema describing the data to submit along with the request",
51
+ "allOf": [{ "$ref": "#" }]
52
+ }
53
+ }
54
+ }
55
+ },
56
+ "allOf": [{ "$ref": "http://json-schema.org/draft-06/schema#" }],
57
+ "properties": {
58
+ "additionalItems": {
59
+ "anyOf": [
60
+ { "type": "boolean" },
61
+ { "$ref": "#" }
62
+ ]
63
+ },
64
+ "additionalProperties": {
65
+ "anyOf": [
66
+ { "type": "boolean" },
67
+ { "$ref": "#" }
68
+ ]
69
+ },
70
+ "dependencies": {
71
+ "additionalProperties": {
72
+ "anyOf": [
73
+ { "$ref": "#" },
74
+ { "type": "array" }
75
+ ]
76
+ }
77
+ },
78
+ "items": {
79
+ "anyOf": [
80
+ { "$ref": "#" },
81
+ { "$ref": "#/definitions/schemaArray" }
82
+ ]
83
+ },
84
+ "definitions": {
85
+ "additionalProperties": { "$ref": "#" }
86
+ },
87
+ "patternProperties": {
88
+ "additionalProperties": { "$ref": "#" }
89
+ },
90
+ "properties": {
91
+ "additionalProperties": { "$ref": "#" }
92
+ },
93
+ "allOf": { "$ref": "#/definitions/schemaArray" },
94
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
95
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
96
+ "not": { "$ref": "#" },
97
+ "contains": { "$ref": "#" },
98
+ "propertyNames": { "$ref": "#" },
99
+ "base": {
100
+ "description": "URI Template resolved as for the 'href' keyword in the Link Description Object. The resulting URI Reference is resolved against the current URI base and sets the new URI base for URI references within the instance.",
101
+ "type": "string"
102
+ },
103
+ "links": {
104
+ "type": "array",
105
+ "items": { "$ref": "#/definitions/linkDescription" }
106
+ },
107
+ "media": {
108
+ "type": "object",
109
+ "properties": {
110
+ "type": {
111
+ "description": "A media type, as described in RFC 2046",
112
+ "type": "string"
113
+ },
114
+ "binaryEncoding": {
115
+ "description": "A content encoding scheme, as described in RFC 2045",
116
+ "type": "string"
117
+ }
118
+ }
119
+ },
120
+ "readOnly": {
121
+ "description": "If true, indicates that the value of this property is controlled by the server.",
122
+ "type": "boolean",
123
+ "default": false
124
+ }
125
+ },
126
+ "links": [
127
+ {
128
+ "rel": "self",
129
+ "href": "{+%24id}"
130
+ }
131
+ ]
132
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/hyper-schema#",
3
+ "$id": "http://json-schema.org/draft-06/links#",
4
+ "title": "Link Description Object",
5
+ "type": "object",
6
+ "required": ["href"],
7
+ "properties": {
8
+ "href": {
9
+ "description": "a URI template, as defined by RFC 6570",
10
+ "type": "string",
11
+ "format": "uri-template"
12
+ },
13
+ "hrefSchema": {
14
+ "description": "a schema for validating user input to the URI template, where the input is in the form of a JSON object with property names matching variable names in \"href\"",
15
+ "allOf": [{ "$ref": "#" }]
16
+ },
17
+ "rel": {
18
+ "description": "relation to the target resource of the link",
19
+ "type": "string"
20
+ },
21
+ "title": {
22
+ "description": "a title for the link",
23
+ "type": "string"
24
+ },
25
+ "targetSchema": {
26
+ "description": "JSON Schema describing the link target",
27
+ "allOf": [{ "$ref": "hyper-schema#" }]
28
+ },
29
+ "mediaType": {
30
+ "description": "media type (as defined by RFC 2046) describing the link target",
31
+ "type": "string"
32
+ },
33
+ "submissionEncType": {
34
+ "description": "The media type in which to submit data along with the request",
35
+ "type": "string",
36
+ "default": "application/json"
37
+ },
38
+ "submissionSchema": {
39
+ "description": "Schema describing the data to submit along with the request",
40
+ "allOf": [{ "$ref": "hyper-schema#" }]
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,155 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-06/schema#",
3
+ "$id": "http://json-schema.org/draft-06/schema#",
4
+ "title": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": { "$ref": "#" }
10
+ },
11
+ "nonNegativeInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "nonNegativeIntegerDefault0": {
16
+ "allOf": [
17
+ { "$ref": "#/definitions/nonNegativeInteger" },
18
+ { "default": 0 }
19
+ ]
20
+ },
21
+ "simpleTypes": {
22
+ "enum": [
23
+ "array",
24
+ "boolean",
25
+ "integer",
26
+ "null",
27
+ "number",
28
+ "object",
29
+ "string"
30
+ ]
31
+ },
32
+ "stringArray": {
33
+ "type": "array",
34
+ "items": { "type": "string" },
35
+ "uniqueItems": true,
36
+ "default": []
37
+ }
38
+ },
39
+ "type": ["object", "boolean"],
40
+ "properties": {
41
+ "$id": {
42
+ "type": "string",
43
+ "format": "uri-reference"
44
+ },
45
+ "$schema": {
46
+ "type": "string",
47
+ "format": "uri"
48
+ },
49
+ "$ref": {
50
+ "type": "string",
51
+ "format": "uri-reference"
52
+ },
53
+ "title": {
54
+ "type": "string"
55
+ },
56
+ "description": {
57
+ "type": "string"
58
+ },
59
+ "default": {},
60
+ "examples": {
61
+ "type": "array",
62
+ "items": {}
63
+ },
64
+ "multipleOf": {
65
+ "type": "number",
66
+ "exclusiveMinimum": 0
67
+ },
68
+ "maximum": {
69
+ "type": "number"
70
+ },
71
+ "exclusiveMaximum": {
72
+ "type": "number"
73
+ },
74
+ "minimum": {
75
+ "type": "number"
76
+ },
77
+ "exclusiveMinimum": {
78
+ "type": "number"
79
+ },
80
+ "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
81
+ "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
82
+ "pattern": {
83
+ "type": "string",
84
+ "format": "regex"
85
+ },
86
+ "additionalItems": { "$ref": "#" },
87
+ "items": {
88
+ "anyOf": [
89
+ { "$ref": "#" },
90
+ { "$ref": "#/definitions/schemaArray" }
91
+ ],
92
+ "default": {}
93
+ },
94
+ "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
95
+ "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
96
+ "uniqueItems": {
97
+ "type": "boolean",
98
+ "default": false
99
+ },
100
+ "contains": { "$ref": "#" },
101
+ "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
102
+ "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
103
+ "required": { "$ref": "#/definitions/stringArray" },
104
+ "additionalProperties": { "$ref": "#" },
105
+ "definitions": {
106
+ "type": "object",
107
+ "additionalProperties": { "$ref": "#" },
108
+ "default": {}
109
+ },
110
+ "properties": {
111
+ "type": "object",
112
+ "additionalProperties": { "$ref": "#" },
113
+ "default": {}
114
+ },
115
+ "patternProperties": {
116
+ "type": "object",
117
+ "additionalProperties": { "$ref": "#" },
118
+ "propertyNames": { "format": "regex" },
119
+ "default": {}
120
+ },
121
+ "dependencies": {
122
+ "type": "object",
123
+ "additionalProperties": {
124
+ "anyOf": [
125
+ { "$ref": "#" },
126
+ { "$ref": "#/definitions/stringArray" }
127
+ ]
128
+ }
129
+ },
130
+ "propertyNames": { "$ref": "#" },
131
+ "const": {},
132
+ "enum": {
133
+ "type": "array",
134
+ "minItems": 1,
135
+ "uniqueItems": true
136
+ },
137
+ "type": {
138
+ "anyOf": [
139
+ { "$ref": "#/definitions/simpleTypes" },
140
+ {
141
+ "type": "array",
142
+ "items": { "$ref": "#/definitions/simpleTypes" },
143
+ "minItems": 1,
144
+ "uniqueItems": true
145
+ }
146
+ ]
147
+ },
148
+ "format": { "type": "string" },
149
+ "allOf": { "$ref": "#/definitions/schemaArray" },
150
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
151
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
152
+ "not": { "$ref": "#" }
153
+ },
154
+ "default": {}
155
+ }
@@ -44,6 +44,10 @@ export declare const Errors: {
44
44
  ASYNC_TIMEOUT: string;
45
45
  PARENT_SCHEMA_VALIDATION_FAILED: string;
46
46
  REMOTE_NOT_VALID: string;
47
+ SCHEMA_IS_FALSE: string;
48
+ CONST: string;
49
+ CONTAINS: string;
50
+ PROPERTY_NAMES: string;
47
51
  };
48
52
  export declare class ValidateError extends Error {
49
53
  name: string;
@@ -3,7 +3,8 @@ export type { ErrorCode, ErrorParam, Errors } from './errors.js';
3
3
  export { ValidateError } from './errors.js';
4
4
  export type { FormatValidatorFn, FormatValidatorsOptions } from './format-validators.js';
5
5
  export { getFormatValidators, getRegisteredFormats, getSupportedFormats, isFormatSupported, registerFormat, unregisterFormat, } from './format-validators.js';
6
- export type { JsonSchema, JsonSchemaType } from './json-schema.js';
6
+ export type { JsonSchemaType } from './json-schema.js';
7
+ export type { JsonSchema } from './json-schema-versions.js';
7
8
  export type { Report, SchemaErrorDetail } from './report.js';
8
9
  export type { ZSchema, ZSchemaAsync, ZSchemaAsyncSafe, ZSchemaSafe } from './z-schema.js';
9
10
  export { ValidateOptions, ValidateResponse } from './z-schema-base.js';
@@ -0,0 +1,23 @@
1
+ import type { JsonSchemaCommon, ZSchemaInternalProperties } from './json-schema.js';
2
+ export type JsonSchemaVersion = 'draft-04' | 'draft-06';
3
+ export declare const CURRENT_DEFAULT_SCHEMA_VERSION: JsonSchemaVersion;
4
+ export declare const VERSION_SCHEMA_URL_MAPPING: Record<JsonSchemaVersion, string>;
5
+ export type JsonSchema = JsonSchemaDraft4 | JsonSchemaDraft6;
6
+ export type JsonSchemaAll = JsonSchemaDraft4 & JsonSchemaDraft6;
7
+ export type JsonSchemaInternal = JsonSchema & ZSchemaInternalProperties;
8
+ export type JsonSchemaInternalAll = JsonSchemaAll & ZSchemaInternalProperties;
9
+ export type JsonSchemaInternalD4 = JsonSchemaDraft4 & ZSchemaInternalProperties;
10
+ export type JsonSchemaInternalD6 = JsonSchemaDraft6 & ZSchemaInternalProperties;
11
+ export interface JsonSchemaDraft4 extends JsonSchemaCommon {
12
+ exclusiveMaximum?: boolean;
13
+ exclusiveMinimum?: boolean;
14
+ }
15
+ export interface JsonSchemaDraft6 extends JsonSchemaCommon {
16
+ $id?: string;
17
+ examples?: unknown[];
18
+ const?: unknown;
19
+ contains?: JsonSchema;
20
+ propertyNames?: JsonSchema;
21
+ exclusiveMaximum?: number;
22
+ exclusiveMinimum?: number;
23
+ }