z-schema 12.1.1 → 12.3.1
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.
- package/README.md +2 -2
- package/bin/z-schema +4 -5
- package/cjs/{index.js → index.cjs} +696 -687
- package/cjs/{index.d.ts → index.d.cts} +47 -26
- package/dist/{errors.d.mts → errors.d.ts} +2 -2
- package/dist/{errors.mjs → errors.js} +1 -2
- package/dist/{format-validators.mjs → format-validators.js} +43 -36
- package/dist/{index.d.mts → index.d.ts} +9 -9
- package/dist/{index.mjs → index.js} +3 -3
- package/dist/{json-schema-versions.d.mts → json-schema-versions.d.ts} +34 -3
- package/dist/{json-schema.d.mts → json-schema.d.ts} +7 -7
- package/dist/{json-schema.mjs → json-schema.js} +7 -12
- package/dist/{json-validation.mjs → json-validation.js} +143 -127
- package/dist/{report.d.mts → report.d.ts} +7 -8
- package/dist/{report.mjs → report.js} +28 -31
- package/dist/{schema-cache.d.mts → schema-cache.d.ts} +4 -4
- package/dist/{schema-cache.mjs → schema-cache.js} +10 -11
- package/dist/{schema-compiler.d.mts → schema-compiler.d.ts} +4 -4
- package/dist/{schema-compiler.mjs → schema-compiler.js} +95 -77
- package/dist/{schema-validator.d.mts → schema-validator.d.ts} +5 -5
- package/dist/{schema-validator.mjs → schema-validator.js} +138 -166
- package/dist/utils/{array.mjs → array.js} +4 -3
- package/dist/utils/{base64.mjs → base64.js} +3 -2
- package/dist/utils/{clone.mjs → clone.js} +18 -20
- package/dist/utils/{hostname.mjs → hostname.js} +19 -22
- package/dist/utils/{json.mjs → json.js} +11 -7
- package/dist/utils/{schema-regex.mjs → schema-regex.js} +5 -5
- package/dist/utils/{time.mjs → time.js} +5 -5
- package/dist/utils/unicode.js +22 -0
- package/dist/utils/{what-is.mjs → what-is.js} +1 -2
- package/dist/validation/{array.mjs → array.js} +18 -20
- package/dist/validation/{combinators.mjs → combinators.js} +16 -16
- package/dist/validation/{numeric.mjs → numeric.js} +11 -11
- package/dist/validation/{object.mjs → object.js} +35 -34
- package/dist/validation/{ref.mjs → ref.js} +4 -4
- package/dist/validation/{shared.mjs → shared.js} +12 -11
- package/dist/validation/{string.mjs → string.js} +32 -32
- package/dist/validation/type.js +34 -0
- package/dist/{z-schema-base.d.mts → z-schema-base.d.ts} +11 -12
- package/dist/{z-schema-base.mjs → z-schema-base.js} +45 -40
- package/dist/{z-schema-options.d.mts → z-schema-options.d.ts} +3 -3
- package/dist/{z-schema-options.mjs → z-schema-options.js} +4 -4
- package/dist/{z-schema-reader.d.mts → z-schema-reader.d.ts} +1 -1
- package/dist/{z-schema-versions.mjs → z-schema-versions.js} +21 -21
- package/dist/{z-schema.d.mts → z-schema.d.ts} +5 -13
- package/dist/{z-schema.mjs → z-schema.js} +37 -47
- package/package.json +25 -23
- package/src/errors.ts +1 -2
- package/src/format-validators.ts +139 -59
- package/src/json-schema-versions.ts +56 -2
- package/src/json-schema.ts +10 -9
- package/src/json-validation.ts +189 -146
- package/src/report.ts +37 -49
- package/src/schema-cache.ts +13 -13
- package/src/schema-compiler.ts +170 -117
- package/src/schema-validator.ts +239 -238
- package/src/utils/array.ts +9 -6
- package/src/utils/base64.ts +13 -2
- package/src/utils/clone.ts +28 -30
- package/src/utils/date.ts +6 -3
- package/src/utils/hostname.ts +27 -27
- package/src/utils/json.ts +16 -9
- package/src/utils/properties.ts +2 -2
- package/src/utils/schema-regex.ts +4 -4
- package/src/utils/time.ts +5 -5
- package/src/utils/unicode.ts +12 -5
- package/src/utils/what-is.ts +1 -5
- package/src/validation/array.ts +24 -22
- package/src/validation/combinators.ts +14 -14
- package/src/validation/numeric.ts +14 -28
- package/src/validation/object.ts +32 -36
- package/src/validation/ref.ts +5 -6
- package/src/validation/shared.ts +22 -21
- package/src/validation/string.ts +29 -39
- package/src/validation/type.ts +17 -17
- package/src/z-schema-base.ts +49 -38
- package/src/z-schema-options.ts +4 -3
- package/src/z-schema.ts +35 -45
- package/umd/ZSchema.js +723 -697
- package/umd/ZSchema.min.js +2 -2
- package/umd/package.json +3 -0
- package/dist/utils/unicode.mjs +0 -12
- package/dist/validation/type.mjs +0 -32
- /package/dist/{format-validators.d.mts → format-validators.d.ts} +0 -0
- /package/dist/{json-schema-versions.mjs → json-schema-versions.js} +0 -0
- /package/dist/schemas/{draft-04-schema.mjs → draft-04-schema.js} +0 -0
- /package/dist/schemas/{draft-06-schema.mjs → draft-06-schema.js} +0 -0
- /package/dist/schemas/{draft-07-schema.mjs → draft-07-schema.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-applicator.mjs → draft-2019-09-meta-applicator.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-content.mjs → draft-2019-09-meta-content.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-core.mjs → draft-2019-09-meta-core.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-format.mjs → draft-2019-09-meta-format.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-meta-data.mjs → draft-2019-09-meta-meta-data.js} +0 -0
- /package/dist/schemas/{draft-2019-09-meta-validation.mjs → draft-2019-09-meta-validation.js} +0 -0
- /package/dist/schemas/{draft-2019-09-schema.mjs → draft-2019-09-schema.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-applicator.mjs → draft-2020-12-meta-applicator.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-content.mjs → draft-2020-12-meta-content.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-core.mjs → draft-2020-12-meta-core.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-format-annotation.mjs → draft-2020-12-meta-format-annotation.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-format-assertion.mjs → draft-2020-12-meta-format-assertion.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-meta-data.mjs → draft-2020-12-meta-meta-data.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-unevaluated.mjs → draft-2020-12-meta-unevaluated.js} +0 -0
- /package/dist/schemas/{draft-2020-12-meta-validation.mjs → draft-2020-12-meta-validation.js} +0 -0
- /package/dist/schemas/{draft-2020-12-schema.mjs → draft-2020-12-schema.js} +0 -0
- /package/dist/utils/{constants.mjs → constants.js} +0 -0
- /package/dist/utils/{date.mjs → date.js} +0 -0
- /package/dist/utils/{properties.mjs → properties.js} +0 -0
- /package/dist/utils/{symbols.mjs → symbols.js} +0 -0
- /package/dist/utils/{uri.mjs → uri.js} +0 -0
- /package/dist/{z-schema-reader.mjs → z-schema-reader.js} +0 -0
package/umd/ZSchema.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
11
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
12
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
14
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
15
|
key = keys[i];
|
|
@@ -25,17 +25,6 @@
|
|
|
25
25
|
enumerable: true
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
//#endregion
|
|
28
|
-
//#region src/utils/uri.ts
|
|
29
|
-
const getQueryPath = (uri) => {
|
|
30
|
-
const io = uri.indexOf("#");
|
|
31
|
-
return io === -1 ? void 0 : uri.slice(io + 1);
|
|
32
|
-
};
|
|
33
|
-
const getRemotePath = (uri) => {
|
|
34
|
-
const io = uri.indexOf("#");
|
|
35
|
-
return io === -1 ? uri : uri.slice(0, io);
|
|
36
|
-
};
|
|
37
|
-
const isAbsoluteUri = (uri) => /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(uri);
|
|
38
|
-
//#endregion
|
|
39
28
|
//#region src/utils/constants.ts
|
|
40
29
|
/**
|
|
41
30
|
* Maximum allowed value for {@link ZSchemaOptions.asyncTimeout} in milliseconds.
|
|
@@ -51,6 +40,17 @@
|
|
|
51
40
|
*/
|
|
52
41
|
const MAX_SCHEMA_REGEX_LENGTH = 1e4;
|
|
53
42
|
//#endregion
|
|
43
|
+
//#region src/utils/uri.ts
|
|
44
|
+
const getQueryPath = (uri) => {
|
|
45
|
+
const io = uri.indexOf("#");
|
|
46
|
+
return io === -1 ? void 0 : uri.slice(io + 1);
|
|
47
|
+
};
|
|
48
|
+
const getRemotePath = (uri) => {
|
|
49
|
+
const io = uri.indexOf("#");
|
|
50
|
+
return io === -1 ? uri : uri.slice(0, io);
|
|
51
|
+
};
|
|
52
|
+
const isAbsoluteUri = (uri) => /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(uri);
|
|
53
|
+
//#endregion
|
|
54
54
|
//#region src/utils/what-is.ts
|
|
55
55
|
const whatIs = (what) => {
|
|
56
56
|
if (typeof what === "object") {
|
|
@@ -59,8 +59,7 @@
|
|
|
59
59
|
return "object";
|
|
60
60
|
}
|
|
61
61
|
if (typeof what === "number") {
|
|
62
|
-
if (Number.isFinite(what))
|
|
63
|
-
else return "number";
|
|
62
|
+
if (Number.isFinite(what)) return what % 1 === 0 ? "integer" : "number";
|
|
64
63
|
if (Number.isNaN(what)) return "not-a-number";
|
|
65
64
|
return "unknown-number";
|
|
66
65
|
}
|
|
@@ -72,18 +71,12 @@
|
|
|
72
71
|
function isInteger(value) {
|
|
73
72
|
return typeof value === "number" && Number.isFinite(value) && value % 1 === 0;
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/json-schema.ts
|
|
77
|
-
/**
|
|
78
|
-
* Keywords whose values are not JSON Schema sub-schemas and must not be
|
|
79
|
-
* traversed during schema walking (id collection, reference collection, etc.).
|
|
80
|
-
*/
|
|
81
|
-
const NON_SCHEMA_KEYWORDS = [
|
|
74
|
+
const NON_SCHEMA_KEYWORDS_SET = new Set([
|
|
82
75
|
"enum",
|
|
83
76
|
"const",
|
|
84
77
|
"default",
|
|
85
78
|
"examples"
|
|
86
|
-
];
|
|
79
|
+
]);
|
|
87
80
|
/** Returns true if the key is an internal z-schema property (prefixed with `__$`). */
|
|
88
81
|
const isInternalKey = (key) => key.startsWith("__$");
|
|
89
82
|
const getId = (schema) => {
|
|
@@ -104,7 +97,7 @@
|
|
|
104
97
|
} catch {}
|
|
105
98
|
}
|
|
106
99
|
if (!targetBaseUri || nextBaseUri === targetBaseUri) {
|
|
107
|
-
if (schemaId && (schemaId === id || schemaId
|
|
100
|
+
if (schemaId && (schemaId === id || schemaId.startsWith("#") && schemaId.slice(1) === id)) return schema;
|
|
108
101
|
if (schema.$anchor === id || schema.$dynamicAnchor === id) return schema;
|
|
109
102
|
}
|
|
110
103
|
let result;
|
|
@@ -116,7 +109,7 @@
|
|
|
116
109
|
const keys = Object.keys(schema);
|
|
117
110
|
for (let i = keys.length - 1; i >= 0; i--) {
|
|
118
111
|
const k = keys[i];
|
|
119
|
-
if (isInternalKey(k) ||
|
|
112
|
+
if (isInternalKey(k) || NON_SCHEMA_KEYWORDS_SET.has(k)) continue;
|
|
120
113
|
result = findId(schema[k], id, targetBaseUri, nextBaseUri, maxDepth, _depth + 1);
|
|
121
114
|
if (result) return result;
|
|
122
115
|
}
|
|
@@ -177,11 +170,10 @@
|
|
|
177
170
|
MAX_RECURSION_DEPTH_EXCEEDED: "Maximum recursion depth ({0}) exceeded. If your schema or data is deeply nested and valid, increase the maxRecursionDepth option."
|
|
178
171
|
};
|
|
179
172
|
var ValidateError = class extends Error {
|
|
180
|
-
name;
|
|
173
|
+
name = "ValidateError";
|
|
181
174
|
details;
|
|
182
175
|
constructor(message, details) {
|
|
183
176
|
super(message);
|
|
184
|
-
this.name = "z-schema validation error";
|
|
185
177
|
this.details = details;
|
|
186
178
|
}
|
|
187
179
|
};
|
|
@@ -202,49 +194,48 @@
|
|
|
202
194
|
//#region src/utils/clone.ts
|
|
203
195
|
const shallowClone = (src) => {
|
|
204
196
|
if (src == null || typeof src !== "object") return src;
|
|
205
|
-
let res;
|
|
206
197
|
if (Array.isArray(src)) {
|
|
207
|
-
res = [];
|
|
198
|
+
const res = [];
|
|
208
199
|
for (let i = 0; i < src.length; i++) res[i] = src[i];
|
|
209
|
-
|
|
210
|
-
res = {};
|
|
211
|
-
const keys = Object.keys(src).sort();
|
|
212
|
-
for (const key of keys) copyProp(src, res, key);
|
|
200
|
+
return res;
|
|
213
201
|
}
|
|
202
|
+
const res = {};
|
|
203
|
+
const keys = Object.keys(src).sort();
|
|
204
|
+
for (let i = 0; i < keys.length; i++) copyProp(src, res, keys[i]);
|
|
214
205
|
return res;
|
|
215
206
|
};
|
|
216
207
|
const deepClone = (src, maxDepth = 100) => {
|
|
217
208
|
let vidx = 0;
|
|
218
209
|
const visited = /* @__PURE__ */ new Map();
|
|
219
210
|
const cloned = [];
|
|
220
|
-
const cloneDeepInner = (
|
|
221
|
-
if (typeof
|
|
211
|
+
const cloneDeepInner = (node, _depth) => {
|
|
212
|
+
if (typeof node !== "object" || node === null) return node;
|
|
222
213
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in deepClone. If your schema or data is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
223
|
-
|
|
224
|
-
const cidx = visited.get(src);
|
|
214
|
+
const cidx = visited.get(node);
|
|
225
215
|
if (cidx !== void 0) return cloned[cidx];
|
|
226
|
-
visited.set(
|
|
227
|
-
if (Array.isArray(
|
|
228
|
-
res = [];
|
|
216
|
+
visited.set(node, vidx++);
|
|
217
|
+
if (Array.isArray(node)) {
|
|
218
|
+
const res = [];
|
|
229
219
|
cloned.push(res);
|
|
230
|
-
for (let i = 0; i <
|
|
231
|
-
|
|
232
|
-
res = {};
|
|
233
|
-
cloned.push(res);
|
|
234
|
-
const keys = Object.keys(src).sort();
|
|
235
|
-
for (const key of keys) copyProp(src, res, key, (v) => cloneDeepInner(v, _depth + 1));
|
|
220
|
+
for (let i = 0; i < node.length; i++) res[i] = cloneDeepInner(node[i], _depth + 1);
|
|
221
|
+
return res;
|
|
236
222
|
}
|
|
223
|
+
const res = {};
|
|
224
|
+
cloned.push(res);
|
|
225
|
+
const keys = Object.keys(node).sort();
|
|
226
|
+
for (let i = 0; i < keys.length; i++) copyProp(node, res, keys[i], (v) => cloneDeepInner(v, _depth + 1));
|
|
237
227
|
return res;
|
|
238
228
|
};
|
|
239
229
|
return cloneDeepInner(src, 0);
|
|
240
230
|
};
|
|
241
231
|
//#endregion
|
|
242
232
|
//#region src/utils/json.ts
|
|
233
|
+
const sortedKeys = (obj) => Object.keys(obj).sort();
|
|
243
234
|
const areEqual = (json1, json2, options, _depth = 0) => {
|
|
244
235
|
const caseInsensitiveComparison = options?.caseInsensitiveComparison || false;
|
|
245
236
|
const maxDepth = options?.maxDepth ?? 100;
|
|
246
237
|
if (json1 === json2) return true;
|
|
247
|
-
if (caseInsensitiveComparison
|
|
238
|
+
if (caseInsensitiveComparison && typeof json1 === "string" && typeof json2 === "string" && json1.toUpperCase() === json2.toUpperCase()) return true;
|
|
248
239
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in areEqual. If your data is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
249
240
|
let i, len;
|
|
250
241
|
if (Array.isArray(json1) && Array.isArray(json2)) {
|
|
@@ -262,13 +253,16 @@
|
|
|
262
253
|
}
|
|
263
254
|
return false;
|
|
264
255
|
};
|
|
265
|
-
const decodeJSONPointer = (str) =>
|
|
266
|
-
return decodeURIComponent(str).replace(/~[0-1]/g, (x) => x === "~1" ? "/" : "~");
|
|
267
|
-
};
|
|
268
|
-
const sortedKeys = (obj) => Object.keys(obj).sort();
|
|
256
|
+
const decodeJSONPointer = (str) => decodeURIComponent(str).replaceAll(/~[0-1]/g, (x) => x === "~1" ? "/" : "~");
|
|
269
257
|
const get = (obj, path) => {
|
|
270
258
|
if (typeof path === "string") path = path.split(".");
|
|
271
|
-
|
|
259
|
+
let acc = obj;
|
|
260
|
+
for (let i = 0; i < path.length; i++) {
|
|
261
|
+
const key = path[i];
|
|
262
|
+
if (acc && acc[key] !== void 0) acc = acc[key];
|
|
263
|
+
else return;
|
|
264
|
+
}
|
|
265
|
+
return acc;
|
|
272
266
|
};
|
|
273
267
|
//#endregion
|
|
274
268
|
//#region src/utils/symbols.ts
|
|
@@ -298,8 +292,8 @@
|
|
|
298
292
|
if (parentOrOptions instanceof Report) {
|
|
299
293
|
this.reportOptions = reportOptionsOrValidate || {};
|
|
300
294
|
this.validateOptions = validateOptions || parentOrOptions.validateOptions;
|
|
301
|
-
this.__$recursiveAnchorStack =
|
|
302
|
-
this.__$dynamicScopeStack =
|
|
295
|
+
this.__$recursiveAnchorStack = parentOrOptions.__$recursiveAnchorStack.slice();
|
|
296
|
+
this.__$dynamicScopeStack = parentOrOptions.__$dynamicScopeStack.slice();
|
|
303
297
|
this.__validationResultCache = parentOrOptions.__validationResultCache;
|
|
304
298
|
} else {
|
|
305
299
|
this.reportOptions = {};
|
|
@@ -382,30 +376,24 @@
|
|
|
382
376
|
setTimeout(checkTimeout, ASYNC_TIMEOUT_POLL_MS);
|
|
383
377
|
}
|
|
384
378
|
getPath(returnPathAsString) {
|
|
385
|
-
|
|
386
|
-
if (
|
|
387
|
-
path = path.concat(this.path);
|
|
388
|
-
if (returnPathAsString !== true) return "#/" + path.map(function(segment) {
|
|
379
|
+
const path = this.parentReport ? this.parentReport.path.concat(this.path) : this.path.slice();
|
|
380
|
+
if (returnPathAsString !== true) return `#/${path.map((segment) => {
|
|
389
381
|
segment = segment.toString();
|
|
390
|
-
if (isAbsoluteUri(segment)) return
|
|
391
|
-
return segment.
|
|
392
|
-
}).join("/")
|
|
382
|
+
if (isAbsoluteUri(segment)) return `uri(${segment})`;
|
|
383
|
+
return segment.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
384
|
+
}).join("/")}`;
|
|
393
385
|
return path;
|
|
394
386
|
}
|
|
395
387
|
getSchemaPath() {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
schemaPath = schemaPath.concat(this.schemaPath);
|
|
399
|
-
return schemaPath;
|
|
388
|
+
if (this.parentReport) return this.parentReport.schemaPath.concat(this.schemaPath);
|
|
389
|
+
return this.schemaPath.slice();
|
|
400
390
|
}
|
|
401
391
|
getSchemaId() {
|
|
402
392
|
if (!this.rootSchema) return;
|
|
403
|
-
|
|
404
|
-
if (this.parentReport) path = path.concat(this.parentReport.path);
|
|
405
|
-
path = path.concat(this.path);
|
|
393
|
+
const path = this.parentReport ? this.parentReport.path.concat(this.path) : this.path.slice();
|
|
406
394
|
while (path.length > 0) {
|
|
407
395
|
const obj = get(this.rootSchema, path);
|
|
408
|
-
if (obj && obj.id) return obj.id;
|
|
396
|
+
if (isObject(obj) && typeof obj.id === "string") return obj.id;
|
|
409
397
|
path.pop();
|
|
410
398
|
}
|
|
411
399
|
return this.rootSchema.id;
|
|
@@ -428,11 +416,11 @@
|
|
|
428
416
|
}
|
|
429
417
|
addCustomError(errorCode, errorMessage, params, subReports, schema, keyword) {
|
|
430
418
|
if (typeof this.reportOptions.maxErrors === "number" && this.errors.length >= this.reportOptions.maxErrors) return;
|
|
431
|
-
if (!errorMessage) throw new Error(
|
|
432
|
-
params
|
|
419
|
+
if (!errorMessage) throw new Error(`No errorMessage known for code ${errorCode}`);
|
|
420
|
+
params ||= [];
|
|
433
421
|
for (let idx = 0; idx < params.length; idx++) {
|
|
434
422
|
const param = params[idx] === null || isObject(params[idx]) ? JSON.stringify(params[idx]) : params[idx];
|
|
435
|
-
errorMessage = errorMessage.replace(
|
|
423
|
+
errorMessage = errorMessage.replace(`{${idx}}`, param.toString());
|
|
436
424
|
}
|
|
437
425
|
const err = {
|
|
438
426
|
code: errorCode,
|
|
@@ -441,10 +429,10 @@
|
|
|
441
429
|
path: this.getPath(this.options.reportPathAsArray),
|
|
442
430
|
schemaPath: this.getSchemaPath(),
|
|
443
431
|
schemaId: this.getSchemaId(),
|
|
444
|
-
keyword
|
|
432
|
+
keyword,
|
|
433
|
+
[schemaSymbol]: schema,
|
|
434
|
+
[jsonSymbol]: this.getJson()
|
|
445
435
|
};
|
|
446
|
-
err[schemaSymbol] = schema;
|
|
447
|
-
err[jsonSymbol] = this.getJson();
|
|
448
436
|
if (schema && typeof schema === "string") err.description = schema;
|
|
449
437
|
else if (schema && typeof schema === "object") {
|
|
450
438
|
if (schema.title) err.title = schema.title;
|
|
@@ -453,7 +441,10 @@
|
|
|
453
441
|
if (subReports != null) {
|
|
454
442
|
if (!Array.isArray(subReports)) subReports = [subReports];
|
|
455
443
|
err.inner = [];
|
|
456
|
-
for (
|
|
444
|
+
for (let si = 0; si < subReports.length; si++) {
|
|
445
|
+
const errs = subReports[si].errors;
|
|
446
|
+
for (let ei = 0; ei < errs.length; ei++) err.inner.push(errs[ei]);
|
|
447
|
+
}
|
|
457
448
|
if (err.inner.length === 0) err.inner = void 0;
|
|
458
449
|
}
|
|
459
450
|
if (Array.isArray(this.validateOptions.excludeErrors) && this.validateOptions.excludeErrors.includes(errorCode)) return;
|
|
@@ -503,7 +494,7 @@
|
|
|
503
494
|
let normalized;
|
|
504
495
|
if (typeof options === "object") {
|
|
505
496
|
let keys = Object.keys(options);
|
|
506
|
-
for (const key of keys) if (defaultOptions[key] === void 0) throw new Error(
|
|
497
|
+
for (const key of keys) if (defaultOptions[key] === void 0) throw new Error(`Unexpected option passed to constructor: ${key}`);
|
|
507
498
|
keys = Object.keys(defaultOptions);
|
|
508
499
|
for (const key of keys) if (options[key] === void 0) options[key] = shallowClone(defaultOptions[key]);
|
|
509
500
|
normalized = options;
|
|
@@ -531,7 +522,7 @@
|
|
|
531
522
|
}
|
|
532
523
|
const getEffectiveId = (schema) => {
|
|
533
524
|
let id = getId(schema);
|
|
534
|
-
if ((!id || !isAbsoluteUri(id)) && typeof schema.id === "string" && isAbsoluteUri(schema.id)) id = schema
|
|
525
|
+
if ((!id || !isAbsoluteUri(id)) && typeof schema.id === "string" && isAbsoluteUri(schema.id)) ({id} = schema);
|
|
535
526
|
return id;
|
|
536
527
|
};
|
|
537
528
|
/**
|
|
@@ -540,9 +531,7 @@
|
|
|
540
531
|
* the instance `validator.setRemoteReference()` (instance cache).
|
|
541
532
|
*/
|
|
542
533
|
function prepareRemoteSchema(schema, uri, validationOptions, maxCloneDepth) {
|
|
543
|
-
|
|
544
|
-
if (typeof schema === "string") _schema = JSON.parse(schema);
|
|
545
|
-
else _schema = deepClone(schema, maxCloneDepth);
|
|
534
|
+
const _schema = typeof schema === "string" ? JSON.parse(schema) : deepClone(schema, maxCloneDepth);
|
|
546
535
|
if (!_schema.id) _schema.id = uri;
|
|
547
536
|
if (validationOptions) _schema.__$validationOptions = normalizeOptions(validationOptions);
|
|
548
537
|
return _schema;
|
|
@@ -550,6 +539,7 @@
|
|
|
550
539
|
var SchemaCache = class SchemaCache {
|
|
551
540
|
static global_cache = Object.create(null);
|
|
552
541
|
cache = Object.create(null);
|
|
542
|
+
validator;
|
|
553
543
|
constructor(validator) {
|
|
554
544
|
this.validator = validator;
|
|
555
545
|
}
|
|
@@ -626,7 +616,7 @@
|
|
|
626
616
|
usesAncestorReport = true;
|
|
627
617
|
} else {
|
|
628
618
|
remoteReport = new Report(report);
|
|
629
|
-
const noCache = result.id && isAbsoluteUri(result.id)
|
|
619
|
+
const noCache = !(result.id && isAbsoluteUri(result.id));
|
|
630
620
|
if (this.validator.sc.compileSchema(remoteReport, result, { noCache })) {
|
|
631
621
|
const savedOptions = this.validator.options;
|
|
632
622
|
try {
|
|
@@ -1728,9 +1718,18 @@
|
|
|
1728
1718
|
var require_merge = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1729
1719
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1730
1720
|
exports.default = merge;
|
|
1721
|
+
function _typeof(o) {
|
|
1722
|
+
"@babel/helpers - typeof";
|
|
1723
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
1724
|
+
return typeof o;
|
|
1725
|
+
} : function(o) {
|
|
1726
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1727
|
+
}, _typeof(o);
|
|
1728
|
+
}
|
|
1731
1729
|
function merge() {
|
|
1732
1730
|
var obj = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1733
1731
|
var defaults = arguments.length > 1 ? arguments[1] : void 0;
|
|
1732
|
+
if (_typeof(obj) !== "object" || obj === null) obj = {};
|
|
1734
1733
|
for (var key in defaults) if (typeof obj[key] === "undefined") obj[key] = defaults[key];
|
|
1735
1734
|
return obj;
|
|
1736
1735
|
}
|
|
@@ -1957,8 +1956,8 @@
|
|
|
1957
1956
|
module.exports.default = exports.default;
|
|
1958
1957
|
}));
|
|
1959
1958
|
//#endregion
|
|
1960
|
-
//#region
|
|
1961
|
-
var
|
|
1959
|
+
//#region node_modules/validator/lib/isURL.js
|
|
1960
|
+
var require_isURL = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1962
1961
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1963
1962
|
exports.default = isURL;
|
|
1964
1963
|
var _assertString = _interopRequireDefault(require_assertString());
|
|
@@ -2123,9 +2122,12 @@
|
|
|
2123
2122
|
}
|
|
2124
2123
|
module.exports = exports.default;
|
|
2125
2124
|
module.exports.default = exports.default;
|
|
2126
|
-
}))
|
|
2127
|
-
|
|
2125
|
+
}));
|
|
2126
|
+
//#endregion
|
|
2127
|
+
//#region src/utils/date.ts
|
|
2128
2128
|
var import_isIP = /* @__PURE__ */ __toESM(require_isIP(), 1);
|
|
2129
|
+
var import_isEmail = /* @__PURE__ */ __toESM(require_isEmail(), 1);
|
|
2130
|
+
var import_isURL = /* @__PURE__ */ __toESM(require_isURL(), 1);
|
|
2129
2131
|
const isLeapYear = (year) => year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
2130
2132
|
const getDaysInMonth = (year, month) => {
|
|
2131
2133
|
switch (month) {
|
|
@@ -2291,8 +2293,8 @@
|
|
|
2291
2293
|
let k = 0;
|
|
2292
2294
|
delta = firstTime ? floor(delta / damp) : delta >> 1;
|
|
2293
2295
|
delta += floor(delta / numPoints);
|
|
2294
|
-
for (; delta >
|
|
2295
|
-
return floor(k +
|
|
2296
|
+
for (; delta > 455; k += base) delta = floor(delta / baseMinusTMin);
|
|
2297
|
+
return floor(k + 36 * delta / (delta + skew));
|
|
2296
2298
|
};
|
|
2297
2299
|
/**
|
|
2298
2300
|
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
|
|
@@ -2417,7 +2419,19 @@
|
|
|
2417
2419
|
});
|
|
2418
2420
|
};
|
|
2419
2421
|
module.exports = {
|
|
2422
|
+
/**
|
|
2423
|
+
* A string representing the current Punycode.js version number.
|
|
2424
|
+
* @memberOf punycode
|
|
2425
|
+
* @type String
|
|
2426
|
+
*/
|
|
2420
2427
|
"version": "2.3.1",
|
|
2428
|
+
/**
|
|
2429
|
+
* An object of methods to convert from JavaScript's internal character
|
|
2430
|
+
* representation (UCS-2) to Unicode code points, and back.
|
|
2431
|
+
* @see <https://mathiasbynens.be/notes/javascript-encoding>
|
|
2432
|
+
* @memberOf punycode
|
|
2433
|
+
* @type Object
|
|
2434
|
+
*/
|
|
2421
2435
|
"ucs2": {
|
|
2422
2436
|
"decode": ucs2decode,
|
|
2423
2437
|
"encode": ucs2encode
|
|
@@ -2428,13 +2442,16 @@
|
|
|
2428
2442
|
"toUnicode": toUnicode
|
|
2429
2443
|
};
|
|
2430
2444
|
})))(), 1);
|
|
2431
|
-
const IDN_SEPARATOR_REGEX = /[\u3002\
|
|
2432
|
-
const IDN_SEPARATOR_TEST_REGEX = /[\u3002\
|
|
2445
|
+
const IDN_SEPARATOR_REGEX = /[\u3002\uFF0E\uFF61]/g;
|
|
2446
|
+
const IDN_SEPARATOR_TEST_REGEX = /[\u3002\uFF0E\uFF61]/;
|
|
2433
2447
|
const splitHostnameLabels = (hostname) => {
|
|
2434
2448
|
if (hostname.length === 0 || hostname.length > 255) return null;
|
|
2435
2449
|
if (hostname.startsWith(".") || hostname.endsWith(".")) return null;
|
|
2436
2450
|
const labels = hostname.split(".");
|
|
2437
|
-
|
|
2451
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2452
|
+
const len = labels[i].length;
|
|
2453
|
+
if (len === 0 || len > 63) return null;
|
|
2454
|
+
}
|
|
2438
2455
|
return labels;
|
|
2439
2456
|
};
|
|
2440
2457
|
const isAsciiHostnameLabel = (label) => /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label);
|
|
@@ -2445,7 +2462,7 @@
|
|
|
2445
2462
|
if (!/^xn--/i.test(label)) return label;
|
|
2446
2463
|
try {
|
|
2447
2464
|
return import_punycode.default.toUnicode(label.toLowerCase());
|
|
2448
|
-
} catch
|
|
2465
|
+
} catch {
|
|
2449
2466
|
return null;
|
|
2450
2467
|
}
|
|
2451
2468
|
};
|
|
@@ -2453,34 +2470,27 @@
|
|
|
2453
2470
|
if (label.startsWith("-") || label.endsWith("-")) return false;
|
|
2454
2471
|
if (label.length >= 4 && label[2] === "-" && label[3] === "-" && !/^xn--/i.test(label)) return false;
|
|
2455
2472
|
if (/^\p{M}/u.test(label)) return false;
|
|
2456
|
-
if (/[\
|
|
2473
|
+
if (/[\u302E\u302F\u0640\u07FA]/u.test(label)) return false;
|
|
2457
2474
|
for (let idx = 0; idx < label.length; idx++) {
|
|
2458
2475
|
const char = label[idx];
|
|
2459
|
-
if (char === "·")
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
if (char === "
|
|
2463
|
-
if (idx === label.length - 1 || !isGreek(label[idx + 1])) return false;
|
|
2464
|
-
}
|
|
2465
|
-
if (char === "׳" || char === "״") {
|
|
2466
|
-
if (idx === 0 || !isHebrew(label[idx - 1])) return false;
|
|
2467
|
-
}
|
|
2468
|
-
if (char === "") {
|
|
2469
|
-
if (idx === 0 || label[idx - 1] !== "्") return false;
|
|
2470
|
-
}
|
|
2476
|
+
if (char === "·" && (idx === 0 || idx === label.length - 1 || label[idx - 1] !== "l" || label[idx + 1] !== "l")) return false;
|
|
2477
|
+
if (char === "͵" && (idx === label.length - 1 || !isGreek(label[idx + 1]))) return false;
|
|
2478
|
+
if ((char === "׳" || char === "״") && (idx === 0 || !isHebrew(label[idx - 1]))) return false;
|
|
2479
|
+
if (char === "" && (idx === 0 || label[idx - 1] !== "्")) return false;
|
|
2471
2480
|
}
|
|
2472
|
-
if (label.includes("・") && !hasCjkKanaOrHan(label.
|
|
2481
|
+
if (label.includes("・") && !hasCjkKanaOrHan(label.replaceAll("・", ""))) return false;
|
|
2473
2482
|
const hasArabicIndic = /[\u0660-\u0669]/.test(label);
|
|
2474
|
-
const hasExtendedArabicIndic = /[\
|
|
2483
|
+
const hasExtendedArabicIndic = /[\u06F0-\u06F9]/.test(label);
|
|
2475
2484
|
if (hasArabicIndic && hasExtendedArabicIndic) return false;
|
|
2476
2485
|
return true;
|
|
2477
2486
|
};
|
|
2478
2487
|
const isValidHostname = (hostname) => {
|
|
2479
|
-
if (IDN_SEPARATOR_TEST_REGEX.test(hostname) || /[^\
|
|
2488
|
+
if (IDN_SEPARATOR_TEST_REGEX.test(hostname) || /[^\u0000-\u007F]/.test(hostname)) return false;
|
|
2480
2489
|
if (import_isIP.default.default(hostname, 4)) return false;
|
|
2481
2490
|
const labels = splitHostnameLabels(hostname);
|
|
2482
2491
|
if (labels === null) return false;
|
|
2483
|
-
for (
|
|
2492
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2493
|
+
const label = labels[i];
|
|
2484
2494
|
if (!isAsciiHostnameLabel(label)) return false;
|
|
2485
2495
|
if (/^xn--/i.test(label)) {
|
|
2486
2496
|
const unicodeLabel = toUnicodeLabel(label);
|
|
@@ -2492,7 +2502,8 @@
|
|
|
2492
2502
|
const isValidIdnHostname = (hostname) => {
|
|
2493
2503
|
const labels = splitHostnameLabels(hostname.replace(IDN_SEPARATOR_REGEX, "."));
|
|
2494
2504
|
if (labels === null) return false;
|
|
2495
|
-
for (
|
|
2505
|
+
for (let i = 0; i < labels.length; i++) {
|
|
2506
|
+
const label = labels[i];
|
|
2496
2507
|
const unicodeLabel = toUnicodeLabel(label);
|
|
2497
2508
|
if (unicodeLabel === null || !isValidIdnUnicodeLabel(unicodeLabel)) return false;
|
|
2498
2509
|
}
|
|
@@ -2513,9 +2524,9 @@
|
|
|
2513
2524
|
const parseRfc3339Time = (time) => {
|
|
2514
2525
|
const matches = RFC3339_TIME_REGEX.exec(time);
|
|
2515
2526
|
if (matches === null) return null;
|
|
2516
|
-
const hour = parseInt(matches[1], 10);
|
|
2517
|
-
const minute = parseInt(matches[2], 10);
|
|
2518
|
-
const second = parseInt(matches[3], 10);
|
|
2527
|
+
const hour = Number.parseInt(matches[1], 10);
|
|
2528
|
+
const minute = Number.parseInt(matches[2], 10);
|
|
2529
|
+
const second = Number.parseInt(matches[3], 10);
|
|
2519
2530
|
if (hour > 23 || minute > 59 || second > 60) return null;
|
|
2520
2531
|
let utcHour = hour;
|
|
2521
2532
|
let utcMinute = minute;
|
|
@@ -2523,8 +2534,8 @@
|
|
|
2523
2534
|
const offsetMatches = /^([+-])([0-9]{2}):([0-9]{2})$/.exec(matches[5]);
|
|
2524
2535
|
if (offsetMatches === null) return null;
|
|
2525
2536
|
const offsetSign = offsetMatches[1];
|
|
2526
|
-
const offsetHour = parseInt(offsetMatches[2], 10);
|
|
2527
|
-
const offsetMinute = parseInt(offsetMatches[3], 10);
|
|
2537
|
+
const offsetHour = Number.parseInt(offsetMatches[2], 10);
|
|
2538
|
+
const offsetMinute = Number.parseInt(offsetMatches[3], 10);
|
|
2528
2539
|
if (offsetHour > 23 || offsetMinute > 59) return null;
|
|
2529
2540
|
const utc = toUtcTime(hour, minute, offsetSign, offsetHour, offsetMinute);
|
|
2530
2541
|
utcHour = utc.hour;
|
|
@@ -2545,17 +2556,18 @@
|
|
|
2545
2556
|
if (typeof date !== "string") return true;
|
|
2546
2557
|
const matches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(date);
|
|
2547
2558
|
if (matches === null) return false;
|
|
2548
|
-
return isValidRfc3339Date(parseInt(matches[1], 10), parseInt(matches[2], 10), parseInt(matches[3], 10));
|
|
2559
|
+
return isValidRfc3339Date(Number.parseInt(matches[1], 10), Number.parseInt(matches[2], 10), Number.parseInt(matches[3], 10));
|
|
2549
2560
|
};
|
|
2550
2561
|
const dateTimeValidator = (dateTime) => {
|
|
2551
2562
|
if (typeof dateTime !== "string") return true;
|
|
2552
|
-
|
|
2553
|
-
if (
|
|
2554
|
-
|
|
2555
|
-
const
|
|
2563
|
+
let tIdx = dateTime.indexOf("T");
|
|
2564
|
+
if (tIdx === -1) tIdx = dateTime.indexOf("t");
|
|
2565
|
+
if (tIdx === -1) return false;
|
|
2566
|
+
const datePart = dateTime.slice(0, tIdx);
|
|
2567
|
+
const timePart = dateTime.slice(tIdx + 1);
|
|
2556
2568
|
const dateMatches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(datePart);
|
|
2557
2569
|
if (dateMatches === null) return false;
|
|
2558
|
-
if (!isValidRfc3339Date(parseInt(dateMatches[1], 10), parseInt(dateMatches[2], 10), parseInt(dateMatches[3], 10))) return false;
|
|
2570
|
+
if (!isValidRfc3339Date(Number.parseInt(dateMatches[1], 10), Number.parseInt(dateMatches[2], 10), Number.parseInt(dateMatches[3], 10))) return false;
|
|
2559
2571
|
return parseRfc3339Time(timePart) !== null;
|
|
2560
2572
|
};
|
|
2561
2573
|
const emailValidator = (email) => {
|
|
@@ -2584,26 +2596,26 @@
|
|
|
2584
2596
|
if (ipv6.includes("%")) return false;
|
|
2585
2597
|
return import_isIP.default.default(ipv6, 6);
|
|
2586
2598
|
};
|
|
2599
|
+
const INVALID_REGEX_ESCAPES = new Set(["a"]);
|
|
2587
2600
|
const regexValidator = (input) => {
|
|
2588
2601
|
if (typeof input !== "string") return true;
|
|
2589
|
-
const invalidEscapes = new Set(["a"]);
|
|
2590
2602
|
for (let idx = 0; idx < input.length; idx++) {
|
|
2591
2603
|
if (input[idx] !== "\\") continue;
|
|
2592
2604
|
idx++;
|
|
2593
2605
|
if (idx >= input.length) return false;
|
|
2594
2606
|
const escaped = input[idx];
|
|
2595
|
-
if (
|
|
2607
|
+
if (INVALID_REGEX_ESCAPES.has(escaped)) return false;
|
|
2596
2608
|
}
|
|
2597
2609
|
try {
|
|
2598
|
-
RegExp(input);
|
|
2610
|
+
new RegExp(input);
|
|
2599
2611
|
return true;
|
|
2600
|
-
} catch
|
|
2612
|
+
} catch {
|
|
2601
2613
|
return false;
|
|
2602
2614
|
}
|
|
2603
2615
|
};
|
|
2604
2616
|
const durationValidator = (input) => {
|
|
2605
2617
|
if (typeof input !== "string") return true;
|
|
2606
|
-
if (!/^P[\
|
|
2618
|
+
if (!/^P[\u0000-\u007F]*$/.test(input)) return false;
|
|
2607
2619
|
if (!input.startsWith("P")) return false;
|
|
2608
2620
|
const body = input.slice(1);
|
|
2609
2621
|
if (body.length === 0) return false;
|
|
@@ -2613,7 +2625,7 @@
|
|
|
2613
2625
|
const datePart = parts[0];
|
|
2614
2626
|
const timePart = parts.length === 2 ? parts[1] : void 0;
|
|
2615
2627
|
if (datePart.length > 0 && !/^(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)$/.test(datePart)) return false;
|
|
2616
|
-
const hasDateComponent =
|
|
2628
|
+
const hasDateComponent = datePart.length > 0;
|
|
2617
2629
|
let hasTimeComponent = false;
|
|
2618
2630
|
if (timePart !== void 0) {
|
|
2619
2631
|
if (timePart.length === 0) return false;
|
|
@@ -2628,32 +2640,31 @@
|
|
|
2628
2640
|
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input);
|
|
2629
2641
|
};
|
|
2630
2642
|
const strictUriValidator = (uri) => typeof uri !== "string" || import_isURL.default.default(uri);
|
|
2643
|
+
const isHexChar = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102;
|
|
2631
2644
|
const hasValidPercentEncoding = (str) => {
|
|
2632
|
-
for (let i = 0; i < str.length; i++) if (str[i] === "%")
|
|
2633
|
-
if (i + 2 >= str.length || !/[0-9a-fA-F]/.test(str[i + 1]) || !/[0-9a-fA-F]/.test(str[i + 2])) return false;
|
|
2634
|
-
}
|
|
2645
|
+
for (let i = 0; i < str.length; i++) if (str[i] === "%" && (i + 2 >= str.length || !isHexChar(str.charCodeAt(i + 1)) || !isHexChar(str.charCodeAt(i + 2)))) return false;
|
|
2635
2646
|
return true;
|
|
2636
2647
|
};
|
|
2637
|
-
const uriValidator =
|
|
2648
|
+
const uriValidator = (uri) => {
|
|
2638
2649
|
if (typeof uri !== "string") return true;
|
|
2639
|
-
if (/[^\
|
|
2650
|
+
if (/[^\u0000-\u007F]/.test(uri)) return false;
|
|
2640
2651
|
if (!hasValidPercentEncoding(uri)) return false;
|
|
2641
|
-
const match =
|
|
2652
|
+
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)/.exec(uri);
|
|
2642
2653
|
if (match) {
|
|
2643
2654
|
const authority = match[2];
|
|
2644
2655
|
const atIndex = authority.indexOf("@");
|
|
2645
2656
|
if (atIndex > 0) {
|
|
2646
|
-
const userinfo = authority.
|
|
2657
|
+
const userinfo = authority.slice(0, atIndex);
|
|
2647
2658
|
if (userinfo.includes("[") || userinfo.includes("]")) return false;
|
|
2648
2659
|
}
|
|
2649
|
-
let hostPort = atIndex
|
|
2660
|
+
let hostPort = atIndex === -1 ? authority : authority.slice(atIndex + 1);
|
|
2650
2661
|
if (hostPort.startsWith("[")) {
|
|
2651
2662
|
const bracketEnd = hostPort.indexOf("]");
|
|
2652
|
-
if (bracketEnd
|
|
2663
|
+
if (bracketEnd !== -1) hostPort = hostPort.slice(bracketEnd + 1);
|
|
2653
2664
|
}
|
|
2654
2665
|
const colonIndex = hostPort.lastIndexOf(":");
|
|
2655
|
-
if (colonIndex
|
|
2656
|
-
const port = hostPort.
|
|
2666
|
+
if (colonIndex !== -1) {
|
|
2667
|
+
const port = hostPort.slice(colonIndex + 1);
|
|
2657
2668
|
if (port.length > 0 && !/^\d+$/.test(port)) return false;
|
|
2658
2669
|
}
|
|
2659
2670
|
}
|
|
@@ -2661,7 +2672,7 @@
|
|
|
2661
2672
|
};
|
|
2662
2673
|
const uriReferenceValidator = (uri) => {
|
|
2663
2674
|
if (typeof uri !== "string") return true;
|
|
2664
|
-
if (/[^\
|
|
2675
|
+
if (/[^\u0000-\u007F]/.test(uri)) return false;
|
|
2665
2676
|
return /^([a-zA-Z][a-zA-Z0-9+.-]*:)?[^"\\<>^{}^`| ]*$/.test(uri);
|
|
2666
2677
|
};
|
|
2667
2678
|
const uriTemplateValidator = (uri) => {
|
|
@@ -2692,20 +2703,20 @@
|
|
|
2692
2703
|
if (typeof pointer !== "string") return true;
|
|
2693
2704
|
if (pointer === "") return true;
|
|
2694
2705
|
if (!/^(?:\/[^/]*)+$/.test(pointer)) return false;
|
|
2695
|
-
const tokens = pointer.split("/")
|
|
2696
|
-
for (
|
|
2706
|
+
const tokens = pointer.split("/");
|
|
2707
|
+
for (let i = 1; i < tokens.length; i++) if (!hasValidTildeEscapes(tokens[i])) return false;
|
|
2697
2708
|
return true;
|
|
2698
2709
|
};
|
|
2699
2710
|
const relativeJsonPointerValidator = (pointer) => {
|
|
2700
2711
|
if (typeof pointer !== "string") return true;
|
|
2701
|
-
const match =
|
|
2712
|
+
const match = /^(0|[1-9]\d*)(.*)$/.exec(pointer);
|
|
2702
2713
|
if (!match) return false;
|
|
2703
2714
|
const suffix = match[2];
|
|
2704
2715
|
if (suffix === "" || suffix === "#") return true;
|
|
2705
2716
|
if (!suffix.startsWith("/")) return false;
|
|
2706
2717
|
if (!/^(?:\/[^/]*)+$/.test(suffix)) return false;
|
|
2707
|
-
const tokens = suffix.split("/")
|
|
2708
|
-
for (
|
|
2718
|
+
const tokens = suffix.split("/");
|
|
2719
|
+
for (let i = 1; i < tokens.length; i++) if (!hasValidTildeEscapes(tokens[i])) return false;
|
|
2709
2720
|
return true;
|
|
2710
2721
|
};
|
|
2711
2722
|
const timeValidator = (time) => {
|
|
@@ -2726,7 +2737,7 @@
|
|
|
2726
2737
|
try {
|
|
2727
2738
|
new URL(iri);
|
|
2728
2739
|
return true;
|
|
2729
|
-
} catch
|
|
2740
|
+
} catch {
|
|
2730
2741
|
return false;
|
|
2731
2742
|
}
|
|
2732
2743
|
};
|
|
@@ -2758,13 +2769,12 @@
|
|
|
2758
2769
|
uuid: uuidValidator
|
|
2759
2770
|
};
|
|
2760
2771
|
const customValidators = {};
|
|
2761
|
-
function
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
};
|
|
2772
|
+
function resolveFormatValidator(name, options) {
|
|
2773
|
+
const custom = options?.customFormats;
|
|
2774
|
+
if (custom && Object.hasOwn(custom, name)) return custom[name];
|
|
2775
|
+
if (Object.hasOwn(customValidators, name)) return customValidators[name];
|
|
2776
|
+
if (options?.strictUris && name === "uri") return strictUriValidator;
|
|
2777
|
+
return inbuiltValidators[name];
|
|
2768
2778
|
}
|
|
2769
2779
|
function registerFormat(name, validatorFunction) {
|
|
2770
2780
|
customValidators[name] = validatorFunction;
|
|
@@ -3617,8 +3627,9 @@
|
|
|
3617
3627
|
if (starHeight > 1) return false;
|
|
3618
3628
|
if (opts.reps > opts.limit) return false;
|
|
3619
3629
|
}
|
|
3620
|
-
|
|
3621
|
-
|
|
3630
|
+
const options = node.options || node.value?.options;
|
|
3631
|
+
if (options) for (i = 0, len = options.length; i < len; i++) {
|
|
3632
|
+
ok = walk({ stack: options[i] }, opts, starHeight);
|
|
3622
3633
|
if (!ok) return false;
|
|
3623
3634
|
}
|
|
3624
3635
|
const stack = node.stack || node.value?.stack;
|
|
@@ -3679,12 +3690,12 @@
|
|
|
3679
3690
|
ok: true,
|
|
3680
3691
|
value: new RegExp(pattern, "u")
|
|
3681
3692
|
};
|
|
3682
|
-
} catch (
|
|
3693
|
+
} catch (error) {
|
|
3683
3694
|
return {
|
|
3684
3695
|
ok: false,
|
|
3685
3696
|
error: {
|
|
3686
3697
|
pattern,
|
|
3687
|
-
message:
|
|
3698
|
+
message: error instanceof Error ? error.message : "Invalid regular expression"
|
|
3688
3699
|
}
|
|
3689
3700
|
};
|
|
3690
3701
|
}
|
|
@@ -3693,12 +3704,12 @@
|
|
|
3693
3704
|
ok: true,
|
|
3694
3705
|
value: new RegExp(pattern)
|
|
3695
3706
|
};
|
|
3696
|
-
} catch (
|
|
3707
|
+
} catch (error) {
|
|
3697
3708
|
return {
|
|
3698
3709
|
ok: false,
|
|
3699
3710
|
error: {
|
|
3700
3711
|
pattern,
|
|
3701
|
-
message:
|
|
3712
|
+
message: error instanceof Error ? error.message : "Invalid regular expression"
|
|
3702
3713
|
}
|
|
3703
3714
|
};
|
|
3704
3715
|
}
|
|
@@ -3727,7 +3738,7 @@
|
|
|
3727
3738
|
const seen = /* @__PURE__ */ new Set();
|
|
3728
3739
|
for (let i = 0; i < l; i++) {
|
|
3729
3740
|
const v = arr[i];
|
|
3730
|
-
const key = typeof v
|
|
3741
|
+
const key = `${typeof v}:${String(v)}`;
|
|
3731
3742
|
if (seen.has(key)) {
|
|
3732
3743
|
if (indexes) for (let j = 0; j < i; j++) {
|
|
3733
3744
|
const prev = arr[j];
|
|
@@ -3742,7 +3753,8 @@
|
|
|
3742
3753
|
}
|
|
3743
3754
|
return true;
|
|
3744
3755
|
}
|
|
3745
|
-
|
|
3756
|
+
const eqOpts = { maxDepth };
|
|
3757
|
+
for (let i = 0; i < l; i++) for (let j = i + 1; j < l; j++) if (areEqual(arr[i], arr[j], eqOpts)) {
|
|
3746
3758
|
if (indexes) indexes.push(i, j);
|
|
3747
3759
|
return false;
|
|
3748
3760
|
}
|
|
@@ -3757,11 +3769,7 @@
|
|
|
3757
3769
|
};
|
|
3758
3770
|
//#endregion
|
|
3759
3771
|
//#region src/validation/shared.ts
|
|
3760
|
-
const shouldSkipValidate =
|
|
3761
|
-
return options && Array.isArray(options.includeErrors) && options.includeErrors.length > 0 && !errors.some(function(err) {
|
|
3762
|
-
return options.includeErrors.includes(err);
|
|
3763
|
-
});
|
|
3764
|
-
};
|
|
3772
|
+
const shouldSkipValidate = (options, errors) => options && Array.isArray(options.includeErrors) && options.includeErrors.length > 0 && !errors.some((err) => options.includeErrors.includes(err));
|
|
3765
3773
|
const supportsDependentKeywords = (schema, version) => {
|
|
3766
3774
|
if (typeof schema.$schema === "string") return !/draft-04|draft-06|draft-07/.test(schema.$schema);
|
|
3767
3775
|
return !(version === "draft-04" || version === "draft-06" || version === "draft-07");
|
|
@@ -3801,7 +3809,7 @@
|
|
|
3801
3809
|
const metaSchema = currentSchemaMeta || rootSchemaMeta;
|
|
3802
3810
|
if (!metaSchema || typeof metaSchema !== "object" || !isObject(metaSchema.$vocabulary)) return true;
|
|
3803
3811
|
const vocabulary = metaSchema.$vocabulary;
|
|
3804
|
-
if (Object.hasOwn(vocabulary, VOCAB_VALIDATION_2019_09) || Object.hasOwn(vocabulary, VOCAB_VALIDATION_2020_12)) return vocabulary[VOCAB_VALIDATION_2019_09]
|
|
3812
|
+
if (Object.hasOwn(vocabulary, VOCAB_VALIDATION_2019_09) || Object.hasOwn(vocabulary, VOCAB_VALIDATION_2020_12)) return vocabulary[VOCAB_VALIDATION_2019_09] || vocabulary[VOCAB_VALIDATION_2020_12];
|
|
3805
3813
|
return false;
|
|
3806
3814
|
};
|
|
3807
3815
|
/**
|
|
@@ -3817,8 +3825,8 @@
|
|
|
3817
3825
|
const metaSchema = currentSchemaMeta || rootSchemaMeta;
|
|
3818
3826
|
if (!metaSchema || typeof metaSchema !== "object" || !isObject(metaSchema.$vocabulary)) return false;
|
|
3819
3827
|
const vocabulary = metaSchema.$vocabulary;
|
|
3820
|
-
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_ASSERTION_2020_12)) return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12]
|
|
3821
|
-
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_2019_09)) return vocabulary[VOCAB_FORMAT_2019_09]
|
|
3828
|
+
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_ASSERTION_2020_12)) return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12];
|
|
3829
|
+
if (Object.hasOwn(vocabulary, VOCAB_FORMAT_2019_09)) return vocabulary[VOCAB_FORMAT_2019_09];
|
|
3822
3830
|
return false;
|
|
3823
3831
|
};
|
|
3824
3832
|
function cacheValidationResult(report, schema, json, passed) {
|
|
@@ -3842,9 +3850,14 @@
|
|
|
3842
3850
|
*/
|
|
3843
3851
|
function deferOrRunSync(report, subReports, decisionFn) {
|
|
3844
3852
|
const asyncTasksBefore = report.asyncTasks.length;
|
|
3845
|
-
for (
|
|
3853
|
+
for (let i = 0; i < subReports.length; i++) {
|
|
3854
|
+
const tasks = subReports[i].asyncTasks;
|
|
3855
|
+
for (let j = 0; j < tasks.length; j++) report.asyncTasks.push(tasks[j]);
|
|
3856
|
+
}
|
|
3846
3857
|
if (report.asyncTasks.length > asyncTasksBefore) report.addAsyncTaskWithPath((callback) => {
|
|
3847
|
-
setTimeout(() =>
|
|
3858
|
+
setTimeout(() => {
|
|
3859
|
+
callback(null);
|
|
3860
|
+
}, 0);
|
|
3848
3861
|
}, [], () => {
|
|
3849
3862
|
decisionFn();
|
|
3850
3863
|
});
|
|
@@ -3852,35 +3865,33 @@
|
|
|
3852
3865
|
}
|
|
3853
3866
|
//#endregion
|
|
3854
3867
|
//#region src/validation/array.ts
|
|
3855
|
-
function additionalItemsValidator(report, schema, json) {
|
|
3856
|
-
if (shouldSkipValidate(
|
|
3868
|
+
function additionalItemsValidator(ctx, report, schema, json) {
|
|
3869
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_ADDITIONAL_ITEMS"])) return;
|
|
3857
3870
|
if (!Array.isArray(json)) return;
|
|
3858
|
-
if (schema.additionalItems === false && Array.isArray(schema.items))
|
|
3859
|
-
if (json.length > schema.items.length) report.addError("ARRAY_ADDITIONAL_ITEMS", void 0, void 0, schema, "additionalItems");
|
|
3860
|
-
}
|
|
3871
|
+
if (schema.additionalItems === false && Array.isArray(schema.items) && json.length > schema.items.length) report.addError("ARRAY_ADDITIONAL_ITEMS", void 0, void 0, schema, "additionalItems");
|
|
3861
3872
|
}
|
|
3862
3873
|
function itemsValidator() {}
|
|
3863
3874
|
function prefixItemsValidator() {}
|
|
3864
|
-
function maxItemsValidator(report, schema, json) {
|
|
3865
|
-
if (shouldSkipValidate(
|
|
3875
|
+
function maxItemsValidator(ctx, report, schema, json) {
|
|
3876
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_LENGTH_LONG"])) return;
|
|
3866
3877
|
if (!Array.isArray(json)) return;
|
|
3867
3878
|
if (json.length > schema.maxItems) report.addError("ARRAY_LENGTH_LONG", [json.length, schema.maxItems], void 0, schema, "maxItems");
|
|
3868
3879
|
}
|
|
3869
|
-
function minItemsValidator(report, schema, json) {
|
|
3870
|
-
if (shouldSkipValidate(
|
|
3880
|
+
function minItemsValidator(ctx, report, schema, json) {
|
|
3881
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_LENGTH_SHORT"])) return;
|
|
3871
3882
|
if (!Array.isArray(json)) return;
|
|
3872
3883
|
if (json.length < schema.minItems) report.addError("ARRAY_LENGTH_SHORT", [json.length, schema.minItems], void 0, schema, "minItems");
|
|
3873
3884
|
}
|
|
3874
|
-
function uniqueItemsValidator(report, schema, json) {
|
|
3875
|
-
if (shouldSkipValidate(
|
|
3885
|
+
function uniqueItemsValidator(ctx, report, schema, json) {
|
|
3886
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ARRAY_UNIQUE"])) return;
|
|
3876
3887
|
if (!Array.isArray(json)) return;
|
|
3877
3888
|
if (schema.uniqueItems === true) {
|
|
3878
3889
|
const matches = [];
|
|
3879
|
-
if (isUniqueArray(json, matches,
|
|
3890
|
+
if (!isUniqueArray(json, matches, ctx.options.maxRecursionDepth)) report.addError("ARRAY_UNIQUE", matches, void 0, schema, "uniqueItems");
|
|
3880
3891
|
}
|
|
3881
3892
|
}
|
|
3882
|
-
function containsValidator(report, schema, json) {
|
|
3883
|
-
if (shouldSkipValidate(
|
|
3893
|
+
function containsValidator(ctx, report, schema, json) {
|
|
3894
|
+
if (shouldSkipValidate(ctx.validateOptions, ["CONTAINS"])) return;
|
|
3884
3895
|
if (!Array.isArray(json)) return;
|
|
3885
3896
|
const containsSchema = schema.contains;
|
|
3886
3897
|
if (containsSchema === void 0) return;
|
|
@@ -3889,16 +3900,16 @@
|
|
|
3889
3900
|
for (let idx = 0; idx < json.length; idx++) {
|
|
3890
3901
|
const subReport = new Report_(report);
|
|
3891
3902
|
subReports.push(subReport);
|
|
3892
|
-
|
|
3903
|
+
ctx._jsonValidate(subReport, containsSchema, json[idx]);
|
|
3893
3904
|
cacheValidationResult(report, containsSchema, json[idx], subReport.errors.length === 0);
|
|
3894
3905
|
}
|
|
3895
3906
|
const addContainsErrorIfNeeded = () => {
|
|
3896
3907
|
let matchingItems = 0;
|
|
3897
|
-
for (
|
|
3898
|
-
const supportsContainsBounds =
|
|
3908
|
+
for (let i = 0; i < subReports.length; i++) if (subReports[i].errors.length === 0) matchingItems += 1;
|
|
3909
|
+
const supportsContainsBounds = ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12";
|
|
3899
3910
|
const minContains = supportsContainsBounds && typeof schema.minContains === "number" ? schema.minContains ?? 1 : 1;
|
|
3900
3911
|
const maxContains = supportsContainsBounds && typeof schema.maxContains === "number" ? schema.maxContains : void 0;
|
|
3901
|
-
if (!(matchingItems >= minContains) || !(maxContains === void 0 || matchingItems <= maxContains)) report.addError("CONTAINS", void 0, subReports, schema
|
|
3912
|
+
if (!(matchingItems >= minContains) || !(maxContains === void 0 || matchingItems <= maxContains)) report.addError("CONTAINS", void 0, subReports, schema);
|
|
3902
3913
|
};
|
|
3903
3914
|
deferOrRunSync(report, subReports, addContainsErrorIfNeeded);
|
|
3904
3915
|
}
|
|
@@ -3906,18 +3917,18 @@
|
|
|
3906
3917
|
function minContainsValidator() {}
|
|
3907
3918
|
//#endregion
|
|
3908
3919
|
//#region src/validation/combinators.ts
|
|
3909
|
-
function allOfValidator(report, schema, json) {
|
|
3920
|
+
function allOfValidator(ctx, report, schema, json) {
|
|
3910
3921
|
for (let i = 0; i < schema.allOf.length; i++) {
|
|
3911
|
-
const validateResult =
|
|
3912
|
-
if (
|
|
3922
|
+
const validateResult = ctx._jsonValidate(report, schema.allOf[i], json);
|
|
3923
|
+
if (ctx.options.breakOnFirstError && !validateResult) break;
|
|
3913
3924
|
}
|
|
3914
3925
|
}
|
|
3915
|
-
function anyOfValidator(report, schema, json) {
|
|
3926
|
+
function anyOfValidator(ctx, report, schema, json) {
|
|
3916
3927
|
const subReports = [];
|
|
3917
3928
|
for (let i = 0; i < schema.anyOf.length; i++) {
|
|
3918
3929
|
const subReport = new Report(report);
|
|
3919
3930
|
subReports.push(subReport);
|
|
3920
|
-
|
|
3931
|
+
ctx._jsonValidate(subReport, schema.anyOf[i], json);
|
|
3921
3932
|
cacheValidationResult(report, schema.anyOf[i], json, subReport.errors.length === 0);
|
|
3922
3933
|
}
|
|
3923
3934
|
deferOrRunSync(report, subReports, () => {
|
|
@@ -3926,15 +3937,15 @@
|
|
|
3926
3937
|
passed = true;
|
|
3927
3938
|
break;
|
|
3928
3939
|
}
|
|
3929
|
-
if (passed
|
|
3940
|
+
if (!passed) report.addError("ANY_OF_MISSING", void 0, subReports, schema, "anyOf");
|
|
3930
3941
|
});
|
|
3931
3942
|
}
|
|
3932
|
-
function oneOfValidator(report, schema, json) {
|
|
3943
|
+
function oneOfValidator(ctx, report, schema, json) {
|
|
3933
3944
|
const subReports = [];
|
|
3934
3945
|
for (let i = 0; i < schema.oneOf.length; i++) {
|
|
3935
3946
|
const subReport = new Report(report);
|
|
3936
3947
|
subReports.push(subReport);
|
|
3937
|
-
|
|
3948
|
+
ctx._jsonValidate(subReport, schema.oneOf[i], json);
|
|
3938
3949
|
cacheValidationResult(report, schema.oneOf[i], json, subReport.errors.length === 0);
|
|
3939
3950
|
}
|
|
3940
3951
|
deferOrRunSync(report, subReports, () => {
|
|
@@ -3944,77 +3955,77 @@
|
|
|
3944
3955
|
else if (passes > 1) report.addError("ONE_OF_MULTIPLE", void 0, void 0, schema, "oneOf");
|
|
3945
3956
|
});
|
|
3946
3957
|
}
|
|
3947
|
-
function notValidator(report, schema, json) {
|
|
3958
|
+
function notValidator(ctx, report, schema, json) {
|
|
3948
3959
|
const subReport = new Report(report);
|
|
3949
|
-
if (
|
|
3960
|
+
if (ctx._jsonValidate(subReport, schema.not, json)) report.addError("NOT_PASSED", void 0, void 0, schema, "not");
|
|
3950
3961
|
}
|
|
3951
|
-
function ifValidator(report, schema, json) {
|
|
3952
|
-
if (
|
|
3962
|
+
function ifValidator(ctx, report, schema, json) {
|
|
3963
|
+
if (ctx.options.version === "draft-04" || ctx.options.version === "draft-06") return;
|
|
3953
3964
|
const conditionSchema = schema.if;
|
|
3954
3965
|
const thenSchema = schema.then;
|
|
3955
3966
|
const elseSchema = schema.else;
|
|
3956
3967
|
if (conditionSchema === void 0 || thenSchema === void 0 && elseSchema === void 0) return;
|
|
3957
3968
|
const conditionReport = new Report(report);
|
|
3958
|
-
|
|
3969
|
+
ctx._jsonValidate(conditionReport, conditionSchema, json);
|
|
3959
3970
|
cacheValidationResult(report, conditionSchema, json, conditionReport.errors.length === 0);
|
|
3960
3971
|
const branchSchema = conditionReport.errors.length === 0 ? thenSchema : elseSchema;
|
|
3961
3972
|
if (branchSchema === void 0) return;
|
|
3962
|
-
|
|
3973
|
+
ctx._jsonValidate(report, branchSchema, json);
|
|
3963
3974
|
}
|
|
3964
3975
|
function thenValidator() {}
|
|
3965
3976
|
function elseValidator() {}
|
|
3966
3977
|
//#endregion
|
|
3967
3978
|
//#region src/validation/numeric.ts
|
|
3968
|
-
function multipleOfValidator(report, schema, json) {
|
|
3969
|
-
if (shouldSkipValidate(
|
|
3979
|
+
function multipleOfValidator(ctx, report, schema, json) {
|
|
3980
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MULTIPLE_OF"])) return;
|
|
3970
3981
|
if (typeof json !== "number") return;
|
|
3971
3982
|
const result = json / schema.multipleOf;
|
|
3972
3983
|
if (!Number.isFinite(result) || Math.abs(result - Math.round(result)) >= 1e-10) report.addError("MULTIPLE_OF", [json, schema.multipleOf], void 0, schema, "multipleOf");
|
|
3973
3984
|
}
|
|
3974
|
-
function maximumValidator(report, schema, json) {
|
|
3975
|
-
if (shouldSkipValidate(
|
|
3985
|
+
function maximumValidator(ctx, report, schema, json) {
|
|
3986
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAXIMUM", "MAXIMUM_EXCLUSIVE"])) return;
|
|
3976
3987
|
if (typeof json !== "number") return;
|
|
3977
3988
|
if (schema.exclusiveMaximum !== true) {
|
|
3978
3989
|
if (json > schema.maximum) report.addError("MAXIMUM", [json, schema.maximum], void 0, schema, "maximum");
|
|
3979
3990
|
} else if (json >= schema.maximum) report.addError("MAXIMUM_EXCLUSIVE", [json, schema.maximum], void 0, schema, "maximum");
|
|
3980
3991
|
}
|
|
3981
|
-
function exclusiveMaximumValidator(report, schema, json) {
|
|
3992
|
+
function exclusiveMaximumValidator(ctx, report, schema, json) {
|
|
3982
3993
|
if (typeof schema.exclusiveMaximum === "number") {
|
|
3983
|
-
if (shouldSkipValidate(
|
|
3994
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAXIMUM_EXCLUSIVE"])) return;
|
|
3984
3995
|
if (typeof json !== "number") return;
|
|
3985
3996
|
if (json >= schema.exclusiveMaximum) report.addError("MAXIMUM_EXCLUSIVE", [json, schema.exclusiveMaximum], void 0, schema, "exclusiveMaximum");
|
|
3986
3997
|
}
|
|
3987
3998
|
}
|
|
3988
|
-
function minimumValidator(report, schema, json) {
|
|
3989
|
-
if (shouldSkipValidate(
|
|
3999
|
+
function minimumValidator(ctx, report, schema, json) {
|
|
4000
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MINIMUM", "MINIMUM_EXCLUSIVE"])) return;
|
|
3990
4001
|
if (typeof json !== "number") return;
|
|
3991
4002
|
if (schema.exclusiveMinimum !== true) {
|
|
3992
4003
|
if (json < schema.minimum) report.addError("MINIMUM", [json, schema.minimum], void 0, schema, "minimum");
|
|
3993
4004
|
} else if (json <= schema.minimum) report.addError("MINIMUM_EXCLUSIVE", [json, schema.minimum], void 0, schema, "minimum");
|
|
3994
4005
|
}
|
|
3995
|
-
function exclusiveMinimumValidator(report, schema, json) {
|
|
4006
|
+
function exclusiveMinimumValidator(ctx, report, schema, json) {
|
|
3996
4007
|
if (typeof schema.exclusiveMinimum === "number") {
|
|
3997
|
-
if (shouldSkipValidate(
|
|
4008
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MINIMUM_EXCLUSIVE"])) return;
|
|
3998
4009
|
if (typeof json !== "number") return;
|
|
3999
4010
|
if (json <= schema.exclusiveMinimum) report.addError("MINIMUM_EXCLUSIVE", [json, schema.exclusiveMinimum], void 0, schema, "exclusiveMinimum");
|
|
4000
4011
|
}
|
|
4001
4012
|
}
|
|
4002
4013
|
//#endregion
|
|
4003
4014
|
//#region src/validation/object.ts
|
|
4004
|
-
function maxPropertiesValidator(report, schema, json) {
|
|
4005
|
-
if (shouldSkipValidate(
|
|
4015
|
+
function maxPropertiesValidator(ctx, report, schema, json) {
|
|
4016
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_PROPERTIES_MAXIMUM"])) return;
|
|
4006
4017
|
if (!isObject(json)) return;
|
|
4007
4018
|
const keysCount = Object.keys(json).length;
|
|
4008
4019
|
if (keysCount > schema.maxProperties) report.addError("OBJECT_PROPERTIES_MAXIMUM", [keysCount, schema.maxProperties], void 0, schema, "maxProperties");
|
|
4009
4020
|
}
|
|
4010
|
-
function minPropertiesValidator(report, schema, json) {
|
|
4011
|
-
if (shouldSkipValidate(
|
|
4021
|
+
function minPropertiesValidator(ctx, report, schema, json) {
|
|
4022
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_PROPERTIES_MINIMUM"])) return;
|
|
4012
4023
|
if (!isObject(json)) return;
|
|
4013
4024
|
const keysCount = Object.keys(json).length;
|
|
4014
4025
|
if (keysCount < schema.minProperties) report.addError("OBJECT_PROPERTIES_MINIMUM", [keysCount, schema.minProperties], void 0, schema, "minProperties");
|
|
4015
4026
|
}
|
|
4016
|
-
function requiredValidator(report, schema, json) {
|
|
4017
|
-
if (shouldSkipValidate(
|
|
4027
|
+
function requiredValidator(ctx, report, schema, json) {
|
|
4028
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_MISSING_REQUIRED_PROPERTY"])) return;
|
|
4018
4029
|
if (!isObject(json)) return;
|
|
4019
4030
|
const idx = schema.required.length;
|
|
4020
4031
|
for (let i = 0; i < idx; i++) {
|
|
@@ -4022,30 +4033,31 @@
|
|
|
4022
4033
|
if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_MISSING_REQUIRED_PROPERTY", [requiredPropertyName], void 0, schema, "required");
|
|
4023
4034
|
}
|
|
4024
4035
|
}
|
|
4025
|
-
function additionalPropertiesValidator(report, schema, json) {
|
|
4026
|
-
if (schema.properties === void 0 && schema.patternProperties === void 0)
|
|
4036
|
+
function additionalPropertiesValidator(ctx, report, schema, json) {
|
|
4037
|
+
if (schema.properties === void 0 && schema.patternProperties === void 0) propertiesValidator(ctx, report, schema, json);
|
|
4027
4038
|
}
|
|
4028
|
-
function patternPropertiesValidator(report, schema, json) {
|
|
4029
|
-
if (schema.properties === void 0)
|
|
4039
|
+
function patternPropertiesValidator(ctx, report, schema, json) {
|
|
4040
|
+
if (schema.properties === void 0) propertiesValidator(ctx, report, schema, json);
|
|
4030
4041
|
}
|
|
4031
|
-
function propertiesValidator(report, schema, json) {
|
|
4032
|
-
if (shouldSkipValidate(
|
|
4042
|
+
function propertiesValidator(ctx, report, schema, json) {
|
|
4043
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_ADDITIONAL_PROPERTIES"])) return;
|
|
4033
4044
|
if (!isObject(json)) return;
|
|
4034
|
-
const properties = schema.properties
|
|
4035
|
-
const patternProperties = schema.patternProperties
|
|
4045
|
+
const properties = schema.properties === void 0 ? {} : schema.properties;
|
|
4046
|
+
const patternProperties = schema.patternProperties === void 0 ? {} : schema.patternProperties;
|
|
4036
4047
|
if (schema.additionalProperties === false) {
|
|
4037
4048
|
let s = Object.keys(json);
|
|
4038
4049
|
const p = Object.keys(properties);
|
|
4039
4050
|
const pp = Object.keys(patternProperties);
|
|
4040
4051
|
s = difference(s, p);
|
|
4041
|
-
for (
|
|
4052
|
+
for (let i = 0; i < pp.length; i++) {
|
|
4053
|
+
const ppKey = pp[i];
|
|
4042
4054
|
const result = compileSchemaRegex(ppKey);
|
|
4043
4055
|
if (!result.ok) continue;
|
|
4044
4056
|
const regExp = result.value;
|
|
4045
|
-
for (let idx2 = s.length - 1; idx2 >= 0; idx2--) if (regExp.test(s[idx2])
|
|
4057
|
+
for (let idx2 = s.length - 1; idx2 >= 0; idx2--) if (regExp.test(s[idx2])) s.splice(idx2, 1);
|
|
4046
4058
|
}
|
|
4047
4059
|
if (s.length > 0) {
|
|
4048
|
-
if (Array.isArray(
|
|
4060
|
+
if (Array.isArray(ctx.options.assumeAdditional)) for (const allowed of ctx.options.assumeAdditional) {
|
|
4049
4061
|
const io = s.indexOf(allowed);
|
|
4050
4062
|
if (io !== -1) s.splice(io, 1);
|
|
4051
4063
|
}
|
|
@@ -4053,29 +4065,29 @@
|
|
|
4053
4065
|
}
|
|
4054
4066
|
}
|
|
4055
4067
|
}
|
|
4056
|
-
function dependenciesValidator(report, schema, json) {
|
|
4057
|
-
if (shouldSkipValidate(
|
|
4068
|
+
function dependenciesValidator(ctx, report, schema, json) {
|
|
4069
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_DEPENDENCY_KEY"])) return;
|
|
4058
4070
|
if (!isObject(json)) return;
|
|
4059
4071
|
const keys = Object.keys(schema.dependencies);
|
|
4060
4072
|
for (const dependencyName of keys) if (Object.hasOwn(json, dependencyName)) {
|
|
4061
4073
|
const dependencyDefinition = schema.dependencies[dependencyName];
|
|
4062
4074
|
if (Array.isArray(dependencyDefinition)) {
|
|
4063
4075
|
for (const requiredPropertyName of dependencyDefinition) if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_DEPENDENCY_KEY", [requiredPropertyName, dependencyName], void 0, schema, "dependencies");
|
|
4064
|
-
} else
|
|
4076
|
+
} else ctx._jsonValidate(report, dependencyDefinition, json);
|
|
4065
4077
|
}
|
|
4066
4078
|
}
|
|
4067
|
-
function dependentSchemasValidator(report, schema, json) {
|
|
4068
|
-
if (!supportsDependentKeywords(schema,
|
|
4079
|
+
function dependentSchemasValidator(ctx, report, schema, json) {
|
|
4080
|
+
if (!supportsDependentKeywords(schema, ctx.options.version)) return;
|
|
4069
4081
|
if (!isObject(json) || !isObject(schema.dependentSchemas)) return;
|
|
4070
4082
|
const keys = Object.keys(schema.dependentSchemas);
|
|
4071
4083
|
for (const dependencyName of keys) if (Object.hasOwn(json, dependencyName)) {
|
|
4072
4084
|
const dependencySchema = schema.dependentSchemas[dependencyName];
|
|
4073
|
-
|
|
4085
|
+
ctx._jsonValidate(report, dependencySchema, json);
|
|
4074
4086
|
}
|
|
4075
4087
|
}
|
|
4076
|
-
function dependentRequiredValidator(report, schema, json) {
|
|
4077
|
-
if (!supportsDependentKeywords(schema,
|
|
4078
|
-
if (shouldSkipValidate(
|
|
4088
|
+
function dependentRequiredValidator(ctx, report, schema, json) {
|
|
4089
|
+
if (!supportsDependentKeywords(schema, ctx.options.version)) return;
|
|
4090
|
+
if (shouldSkipValidate(ctx.validateOptions, ["OBJECT_DEPENDENCY_KEY"])) return;
|
|
4079
4091
|
if (!isObject(json) || !isObject(schema.dependentRequired)) return;
|
|
4080
4092
|
const keys = Object.keys(schema.dependentRequired);
|
|
4081
4093
|
for (const dependencyName of keys) {
|
|
@@ -4085,8 +4097,8 @@
|
|
|
4085
4097
|
for (const requiredPropertyName of requiredProperties) if (!Object.hasOwn(json, requiredPropertyName)) report.addError("OBJECT_DEPENDENCY_KEY", [requiredPropertyName, dependencyName], void 0, schema, "dependentRequired");
|
|
4086
4098
|
}
|
|
4087
4099
|
}
|
|
4088
|
-
function propertyNamesValidator(report, schema, json) {
|
|
4089
|
-
if (shouldSkipValidate(
|
|
4100
|
+
function propertyNamesValidator(ctx, report, schema, json) {
|
|
4101
|
+
if (shouldSkipValidate(ctx.validateOptions, ["PROPERTY_NAMES"])) return;
|
|
4090
4102
|
if (!isObject(json)) return;
|
|
4091
4103
|
const propertyNamesSchema = schema.propertyNames;
|
|
4092
4104
|
if (propertyNamesSchema === void 0) return;
|
|
@@ -4096,10 +4108,10 @@
|
|
|
4096
4108
|
for (const key of keys) {
|
|
4097
4109
|
const subReport = new Report_(report);
|
|
4098
4110
|
subReports.push(subReport);
|
|
4099
|
-
|
|
4111
|
+
ctx._jsonValidate(subReport, propertyNamesSchema, key);
|
|
4100
4112
|
}
|
|
4101
4113
|
const addPropertyNameErrors = () => {
|
|
4102
|
-
for (let idx = 0; idx < keys.length; idx++) if (subReports[idx].errors.length > 0) report.addError("PROPERTY_NAMES", [keys[idx]], subReports[idx], schema
|
|
4114
|
+
for (let idx = 0; idx < keys.length; idx++) if (subReports[idx].errors.length > 0) report.addError("PROPERTY_NAMES", [keys[idx]], subReports[idx], schema);
|
|
4103
4115
|
};
|
|
4104
4116
|
deferOrRunSync(report, subReports, addPropertyNameErrors);
|
|
4105
4117
|
}
|
|
@@ -4109,7 +4121,7 @@
|
|
|
4109
4121
|
const hashIdx = dynamicRef.indexOf("#");
|
|
4110
4122
|
if (hashIdx === -1) return;
|
|
4111
4123
|
const fragment = dynamicRef.slice(hashIdx + 1);
|
|
4112
|
-
if (!fragment || fragment
|
|
4124
|
+
if (!fragment || fragment.startsWith("/")) return;
|
|
4113
4125
|
return fragment;
|
|
4114
4126
|
};
|
|
4115
4127
|
const findDynamicAnchorInScope = (scopeSchema, anchorName) => {
|
|
@@ -4136,7 +4148,7 @@
|
|
|
4136
4148
|
*/
|
|
4137
4149
|
const resolveDynamicRef = (schema, dynamicScopeStack) => {
|
|
4138
4150
|
const resolved = schema.__$dynamicRefResolved;
|
|
4139
|
-
if (
|
|
4151
|
+
if (resolved === void 0 || !schema.$dynamicRef) return resolved;
|
|
4140
4152
|
let target = resolved;
|
|
4141
4153
|
const anchorName = getDynamicRefAnchorName(schema.$dynamicRef);
|
|
4142
4154
|
if (anchorName && typeof target === "object" && target.$dynamicAnchor === anchorName) for (let scopeIdx = 0; scopeIdx < dynamicScopeStack.length; scopeIdx++) {
|
|
@@ -4163,8 +4175,9 @@
|
|
|
4163
4175
|
} catch {
|
|
4164
4176
|
return;
|
|
4165
4177
|
}
|
|
4166
|
-
|
|
4167
|
-
|
|
4178
|
+
const bufferCtor = globalThis.Buffer;
|
|
4179
|
+
if (bufferCtor !== void 0) try {
|
|
4180
|
+
return bufferCtor.from(value, "base64").toString("utf-8");
|
|
4168
4181
|
} catch {
|
|
4169
4182
|
return;
|
|
4170
4183
|
}
|
|
@@ -4173,27 +4186,37 @@
|
|
|
4173
4186
|
//#region src/utils/unicode.ts
|
|
4174
4187
|
/**
|
|
4175
4188
|
* Returns the number of Unicode code points in the string.
|
|
4176
|
-
* Uses
|
|
4189
|
+
* Uses a surrogate-aware charCodeAt scan (equivalent to the string iterator)
|
|
4190
|
+
* that counts a surrogate pair as one code point and lone surrogates as one each.
|
|
4177
4191
|
*/
|
|
4178
4192
|
function unicodeLength(str) {
|
|
4179
|
-
let count =
|
|
4180
|
-
for (
|
|
4193
|
+
let count = str.length;
|
|
4194
|
+
for (let i = 0; i < str.length - 1; i++) {
|
|
4195
|
+
const hi = str.charCodeAt(i);
|
|
4196
|
+
if (hi >= 55296 && hi <= 56319) {
|
|
4197
|
+
const lo = str.charCodeAt(i + 1);
|
|
4198
|
+
if (lo >= 56320 && lo <= 57343) {
|
|
4199
|
+
count--;
|
|
4200
|
+
i++;
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4181
4204
|
return count;
|
|
4182
4205
|
}
|
|
4183
4206
|
//#endregion
|
|
4184
4207
|
//#region src/validation/string.ts
|
|
4185
|
-
function minLengthValidator(report, schema, json) {
|
|
4186
|
-
if (shouldSkipValidate(
|
|
4208
|
+
function minLengthValidator(ctx, report, schema, json) {
|
|
4209
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MIN_LENGTH"])) return;
|
|
4187
4210
|
if (typeof json !== "string") return;
|
|
4188
4211
|
if (unicodeLength(json) < schema.minLength) report.addError("MIN_LENGTH", [json.length, schema.minLength], void 0, schema, "minLength");
|
|
4189
4212
|
}
|
|
4190
|
-
function maxLengthValidator(report, schema, json) {
|
|
4191
|
-
if (shouldSkipValidate(
|
|
4213
|
+
function maxLengthValidator(ctx, report, schema, json) {
|
|
4214
|
+
if (shouldSkipValidate(ctx.validateOptions, ["MAX_LENGTH"])) return;
|
|
4192
4215
|
if (typeof json !== "string") return;
|
|
4193
4216
|
if (unicodeLength(json) > schema.maxLength) report.addError("MAX_LENGTH", [json.length, schema.maxLength], void 0, schema, "maxLength");
|
|
4194
4217
|
}
|
|
4195
|
-
function patternValidator(report, schema, json) {
|
|
4196
|
-
if (shouldSkipValidate(
|
|
4218
|
+
function patternValidator(ctx, report, schema, json) {
|
|
4219
|
+
if (shouldSkipValidate(ctx.validateOptions, ["PATTERN"])) return;
|
|
4197
4220
|
if (typeof json !== "string") return;
|
|
4198
4221
|
const result = compileSchemaRegex(schema.pattern);
|
|
4199
4222
|
if (!result.ok) {
|
|
@@ -4206,46 +4229,46 @@
|
|
|
4206
4229
|
}
|
|
4207
4230
|
if (!result.value.test(json)) report.addError("PATTERN", [schema.pattern, json], void 0, schema, "pattern");
|
|
4208
4231
|
}
|
|
4209
|
-
function formatValidator(report, schema, json) {
|
|
4210
|
-
if (
|
|
4211
|
-
if (
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
const isModernDraft = this.options.version === "draft2019-09" || this.options.version === "draft2020-12";
|
|
4215
|
-
const formatValidatorFn = getFormatValidators(this.options)[schema.format];
|
|
4232
|
+
function formatValidator(ctx, report, schema, json) {
|
|
4233
|
+
if (ctx.options.formatAssertions === false) return;
|
|
4234
|
+
if (ctx.options.formatAssertions === true && !isFormatAssertionVocabEnabled(schema, report, ctx.options.version)) return;
|
|
4235
|
+
const isModernDraft = ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12";
|
|
4236
|
+
const formatValidatorFn = resolveFormatValidator(schema.format, ctx.options);
|
|
4216
4237
|
if (typeof formatValidatorFn === "function") {
|
|
4217
|
-
if (shouldSkipValidate(
|
|
4238
|
+
if (shouldSkipValidate(ctx.validateOptions, ["INVALID_FORMAT"])) return;
|
|
4218
4239
|
if (report.hasError("INVALID_TYPE", [schema.type, whatIs(json)])) return;
|
|
4219
|
-
if (formatValidatorFn.length === 2) report.addAsyncTaskWithPath(formatValidatorFn, [json],
|
|
4240
|
+
if (formatValidatorFn.length === 2) report.addAsyncTaskWithPath(formatValidatorFn, [json], (result) => {
|
|
4220
4241
|
if (result !== true) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4221
4242
|
});
|
|
4222
4243
|
else {
|
|
4223
|
-
const result = formatValidatorFn.call(
|
|
4244
|
+
const result = formatValidatorFn.call(ctx, json);
|
|
4224
4245
|
if (result instanceof Promise) {
|
|
4225
4246
|
const promiseResult = result;
|
|
4226
4247
|
report.addAsyncTaskWithPath(async (callback) => {
|
|
4227
4248
|
try {
|
|
4228
4249
|
callback(await promiseResult);
|
|
4229
|
-
} catch
|
|
4250
|
+
} catch {
|
|
4230
4251
|
callback(false);
|
|
4231
4252
|
}
|
|
4232
|
-
}, [],
|
|
4253
|
+
}, [], (resolvedResult) => {
|
|
4233
4254
|
if (resolvedResult !== true) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4234
4255
|
});
|
|
4235
|
-
} else if (result
|
|
4256
|
+
} else if (!result) report.addError("INVALID_FORMAT", [schema.format, JSON.stringify(json)], void 0, schema, "format");
|
|
4236
4257
|
}
|
|
4237
|
-
} else if (
|
|
4258
|
+
} else if (ctx.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
4238
4259
|
}
|
|
4239
|
-
function contentEncodingValidator(report, schema, json) {
|
|
4240
|
-
if (
|
|
4260
|
+
function contentEncodingValidator(ctx, report, schema, json) {
|
|
4261
|
+
if (ctx.options.version !== "draft-07") return;
|
|
4241
4262
|
if (typeof json !== "string") return;
|
|
4242
|
-
|
|
4263
|
+
const { contentEncoding } = schema;
|
|
4264
|
+
if (contentEncoding !== "base64") return;
|
|
4243
4265
|
if (!isValidBase64(json)) report.addError("INVALID_FORMAT", ["contentEncoding:base64", JSON.stringify(json)], void 0, schema, "contentEncoding");
|
|
4244
4266
|
}
|
|
4245
|
-
function contentMediaTypeValidator(report, schema, json) {
|
|
4246
|
-
if (
|
|
4267
|
+
function contentMediaTypeValidator(ctx, report, schema, json) {
|
|
4268
|
+
if (ctx.options.version !== "draft-07") return;
|
|
4247
4269
|
if (typeof json !== "string") return;
|
|
4248
|
-
|
|
4270
|
+
const { contentMediaType } = schema;
|
|
4271
|
+
if (contentMediaType !== "application/json") return;
|
|
4249
4272
|
let payload = json;
|
|
4250
4273
|
if (schema.contentEncoding === "base64") {
|
|
4251
4274
|
const decoded = decodeBase64(json);
|
|
@@ -4263,38 +4286,40 @@
|
|
|
4263
4286
|
}
|
|
4264
4287
|
//#endregion
|
|
4265
4288
|
//#region src/validation/type.ts
|
|
4266
|
-
function typeValidator(report, schema, json) {
|
|
4267
|
-
if (shouldSkipValidate(
|
|
4289
|
+
function typeValidator(ctx, report, schema, json) {
|
|
4290
|
+
if (shouldSkipValidate(ctx.validateOptions, ["INVALID_TYPE"])) return;
|
|
4268
4291
|
const jsonType = whatIs(json);
|
|
4269
4292
|
if (typeof schema.type === "string") {
|
|
4270
4293
|
if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) report.addError("INVALID_TYPE", [schema.type, jsonType], void 0, schema, "type");
|
|
4271
4294
|
} else if (!schema.type.includes(jsonType) && (jsonType !== "integer" || !schema.type.includes("number"))) report.addError("INVALID_TYPE", [JSON.stringify(schema.type), jsonType], void 0, schema, "type");
|
|
4272
4295
|
}
|
|
4273
|
-
function enumValidator(report, schema, json) {
|
|
4274
|
-
if (shouldSkipValidate(
|
|
4275
|
-
|
|
4276
|
-
|
|
4296
|
+
function enumValidator(ctx, report, schema, json) {
|
|
4297
|
+
if (shouldSkipValidate(ctx.validateOptions, ["ENUM_CASE_MISMATCH", "ENUM_MISMATCH"])) return;
|
|
4298
|
+
const eqOpts = { maxDepth: ctx.options.maxRecursionDepth };
|
|
4299
|
+
const eqOptsCI = {
|
|
4300
|
+
caseInsensitiveComparison: true,
|
|
4301
|
+
maxDepth: ctx.options.maxRecursionDepth
|
|
4302
|
+
};
|
|
4303
|
+
let caseInsensitiveMatch = false, match = false;
|
|
4304
|
+
for (const enumVal of schema.enum) if (areEqual(json, enumVal, eqOpts)) {
|
|
4277
4305
|
match = true;
|
|
4278
4306
|
break;
|
|
4279
|
-
} else if (areEqual(json, enumVal,
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
})) caseInsensitiveMatch = true;
|
|
4283
|
-
if (match === false) {
|
|
4284
|
-
const error = caseInsensitiveMatch && this.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
|
|
4307
|
+
} else if (areEqual(json, enumVal, eqOptsCI)) caseInsensitiveMatch = true;
|
|
4308
|
+
if (!match) {
|
|
4309
|
+
const error = caseInsensitiveMatch && ctx.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
|
|
4285
4310
|
report.addError(error, [JSON.stringify(json)], void 0, schema, "enum");
|
|
4286
4311
|
}
|
|
4287
4312
|
}
|
|
4288
|
-
function constValidator(report, schema, json) {
|
|
4313
|
+
function constValidator(ctx, report, schema, json) {
|
|
4289
4314
|
const constValue = schema.const;
|
|
4290
|
-
if (areEqual(json, constValue, { maxDepth:
|
|
4315
|
+
if (!areEqual(json, constValue, { maxDepth: ctx.options.maxRecursionDepth })) report.addError("CONST", [JSON.stringify(constValue)], void 0, schema);
|
|
4291
4316
|
}
|
|
4292
4317
|
//#endregion
|
|
4293
4318
|
//#region src/json-validation.ts
|
|
4294
|
-
function collectEvaluated(args) {
|
|
4319
|
+
function collectEvaluated(ctx, args) {
|
|
4295
4320
|
const { report, currentSchema, json, mode, depth } = args;
|
|
4296
4321
|
if (!currentSchema || typeof currentSchema === "boolean") return /* @__PURE__ */ new Set();
|
|
4297
|
-
if (depth > (
|
|
4322
|
+
if (depth > (ctx.options.maxRecursionDepth ?? 100)) {
|
|
4298
4323
|
report.addError("COLLECT_EVALUATED_DEPTH_EXCEEDED", [depth]);
|
|
4299
4324
|
return /* @__PURE__ */ new Set();
|
|
4300
4325
|
}
|
|
@@ -4305,7 +4330,7 @@
|
|
|
4305
4330
|
return false;
|
|
4306
4331
|
};
|
|
4307
4332
|
const recurse = (subSchema) => {
|
|
4308
|
-
if (mode === "items") return collectEvaluated
|
|
4333
|
+
if (mode === "items") return collectEvaluated(ctx, {
|
|
4309
4334
|
report,
|
|
4310
4335
|
currentSchema: subSchema,
|
|
4311
4336
|
json,
|
|
@@ -4313,7 +4338,7 @@
|
|
|
4313
4338
|
jsonArr: args.jsonArr,
|
|
4314
4339
|
depth: depth + 1
|
|
4315
4340
|
});
|
|
4316
|
-
return collectEvaluated
|
|
4341
|
+
return collectEvaluated(ctx, {
|
|
4317
4342
|
report,
|
|
4318
4343
|
currentSchema: subSchema,
|
|
4319
4344
|
json,
|
|
@@ -4323,7 +4348,7 @@
|
|
|
4323
4348
|
});
|
|
4324
4349
|
};
|
|
4325
4350
|
if (mode === "items") {
|
|
4326
|
-
const jsonArr = args
|
|
4351
|
+
const { jsonArr } = args;
|
|
4327
4352
|
if (Array.isArray(currentSchema.prefixItems)) {
|
|
4328
4353
|
const len = Math.min(currentSchema.prefixItems.length, jsonArr.length);
|
|
4329
4354
|
for (let i = 0; i < len; i++) evaluated.add(i);
|
|
@@ -4339,104 +4364,102 @@
|
|
|
4339
4364
|
let passed = getCachedValidationResult(report, currentSchema.contains, jsonArr[i]);
|
|
4340
4365
|
if (passed === void 0) {
|
|
4341
4366
|
const subReport = new Report(report);
|
|
4342
|
-
validate
|
|
4367
|
+
validate(ctx, subReport, currentSchema.contains, jsonArr[i]);
|
|
4343
4368
|
passed = subReport.errors.length === 0;
|
|
4344
4369
|
}
|
|
4345
4370
|
if (passed) evaluated.add(i);
|
|
4346
4371
|
}
|
|
4347
4372
|
if (currentSchema.unevaluatedItems === true) return "all";
|
|
4348
4373
|
} else {
|
|
4349
|
-
const jsonData = args
|
|
4374
|
+
const { jsonData } = args;
|
|
4350
4375
|
if (isObject(currentSchema.properties)) {
|
|
4351
|
-
|
|
4376
|
+
const propKeysCE = Object.keys(currentSchema.properties);
|
|
4377
|
+
for (let i = 0; i < propKeysCE.length; i++) {
|
|
4378
|
+
const key = propKeysCE[i];
|
|
4379
|
+
if (Object.hasOwn(jsonData, key)) evaluated.add(key);
|
|
4380
|
+
}
|
|
4352
4381
|
}
|
|
4353
4382
|
if (isObject(currentSchema.patternProperties)) for (const pattern of Object.keys(currentSchema.patternProperties)) {
|
|
4354
4383
|
const result = compileSchemaRegex(pattern);
|
|
4355
4384
|
if (result.ok) {
|
|
4356
|
-
|
|
4385
|
+
const jdKeys = Object.keys(jsonData);
|
|
4386
|
+
for (let i = 0; i < jdKeys.length; i++) if (result.value.test(jdKeys[i])) evaluated.add(jdKeys[i]);
|
|
4357
4387
|
}
|
|
4358
4388
|
}
|
|
4359
4389
|
if (currentSchema.additionalProperties !== void 0) {
|
|
4360
|
-
const
|
|
4390
|
+
const propKeySet = new Set(isObject(currentSchema.properties) ? Object.keys(currentSchema.properties) : []);
|
|
4361
4391
|
const patternRegexes = [];
|
|
4362
4392
|
if (isObject(currentSchema.patternProperties)) for (const pattern of Object.keys(currentSchema.patternProperties)) {
|
|
4363
4393
|
const result = compileSchemaRegex(pattern);
|
|
4364
4394
|
if (result.ok) patternRegexes.push(result.value);
|
|
4365
4395
|
}
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4396
|
+
const apKeys = Object.keys(jsonData);
|
|
4397
|
+
for (let i = 0; i < apKeys.length; i++) {
|
|
4398
|
+
const key = apKeys[i];
|
|
4399
|
+
if (propKeySet.has(key)) continue;
|
|
4400
|
+
let matchedPattern = false;
|
|
4401
|
+
for (let pi = 0; pi < patternRegexes.length; pi++) if (patternRegexes[pi].test(key)) {
|
|
4402
|
+
matchedPattern = true;
|
|
4403
|
+
break;
|
|
4404
|
+
}
|
|
4405
|
+
if (matchedPattern) continue;
|
|
4369
4406
|
evaluated.add(key);
|
|
4370
4407
|
}
|
|
4371
4408
|
}
|
|
4372
4409
|
if (isObject(currentSchema.dependentSchemas)) {
|
|
4373
|
-
for (const [depKey, depSchema] of Object.entries(currentSchema.dependentSchemas)) if (Object.hasOwn(jsonData, depKey))
|
|
4374
|
-
if (merge(recurse(depSchema))) return "all";
|
|
4375
|
-
}
|
|
4410
|
+
for (const [depKey, depSchema] of Object.entries(currentSchema.dependentSchemas)) if (Object.hasOwn(jsonData, depKey) && merge(recurse(depSchema))) return "all";
|
|
4376
4411
|
}
|
|
4377
4412
|
if (currentSchema.unevaluatedProperties === true) return "all";
|
|
4378
4413
|
}
|
|
4379
4414
|
if (Array.isArray(currentSchema.allOf)) {
|
|
4380
|
-
for (
|
|
4415
|
+
for (let i = 0; i < currentSchema.allOf.length; i++) if (merge(recurse(currentSchema.allOf[i]))) return "all";
|
|
4381
4416
|
}
|
|
4382
|
-
if (Array.isArray(currentSchema.anyOf)) for (
|
|
4417
|
+
if (Array.isArray(currentSchema.anyOf)) for (let i = 0; i < currentSchema.anyOf.length; i++) {
|
|
4418
|
+
const subSchema = currentSchema.anyOf[i];
|
|
4383
4419
|
let passed = getCachedValidationResult(report, subSchema, json);
|
|
4384
4420
|
if (passed === void 0) {
|
|
4385
4421
|
const subReport = new Report(report);
|
|
4386
|
-
validate
|
|
4422
|
+
validate(ctx, subReport, subSchema, json);
|
|
4387
4423
|
passed = subReport.errors.length === 0;
|
|
4388
4424
|
}
|
|
4389
|
-
if (passed)
|
|
4390
|
-
if (merge(recurse(subSchema))) return "all";
|
|
4391
|
-
}
|
|
4425
|
+
if (passed && merge(recurse(subSchema))) return "all";
|
|
4392
4426
|
}
|
|
4393
|
-
if (Array.isArray(currentSchema.oneOf)) for (
|
|
4427
|
+
if (Array.isArray(currentSchema.oneOf)) for (let i = 0; i < currentSchema.oneOf.length; i++) {
|
|
4428
|
+
const subSchema = currentSchema.oneOf[i];
|
|
4394
4429
|
let passed = getCachedValidationResult(report, subSchema, json);
|
|
4395
4430
|
if (passed === void 0) {
|
|
4396
4431
|
const subReport = new Report(report);
|
|
4397
|
-
validate
|
|
4432
|
+
validate(ctx, subReport, subSchema, json);
|
|
4398
4433
|
passed = subReport.errors.length === 0;
|
|
4399
4434
|
}
|
|
4400
|
-
if (passed)
|
|
4401
|
-
if (merge(recurse(subSchema))) return "all";
|
|
4402
|
-
}
|
|
4435
|
+
if (passed && merge(recurse(subSchema))) return "all";
|
|
4403
4436
|
}
|
|
4404
4437
|
if (currentSchema.if !== void 0) {
|
|
4405
4438
|
let condPassed = getCachedValidationResult(report, currentSchema.if, json);
|
|
4406
4439
|
if (condPassed === void 0) {
|
|
4407
4440
|
const condReport = new Report(report);
|
|
4408
|
-
validate
|
|
4441
|
+
validate(ctx, condReport, currentSchema.if, json);
|
|
4409
4442
|
condPassed = condReport.errors.length === 0;
|
|
4410
4443
|
}
|
|
4411
4444
|
if (condPassed) {
|
|
4412
4445
|
if (merge(recurse(currentSchema.if))) return "all";
|
|
4413
|
-
if (currentSchema.then !== void 0)
|
|
4414
|
-
|
|
4415
|
-
}
|
|
4416
|
-
} else if (currentSchema.else !== void 0) {
|
|
4417
|
-
if (merge(recurse(currentSchema.else))) return "all";
|
|
4418
|
-
}
|
|
4419
|
-
}
|
|
4420
|
-
if (currentSchema.__$refResolved && currentSchema.__$refResolved !== currentSchema) {
|
|
4421
|
-
if (merge(recurse(currentSchema.__$refResolved))) return "all";
|
|
4446
|
+
if (currentSchema.then !== void 0 && merge(recurse(currentSchema.then))) return "all";
|
|
4447
|
+
} else if (currentSchema.else !== void 0 && merge(recurse(currentSchema.else))) return "all";
|
|
4422
4448
|
}
|
|
4449
|
+
if (currentSchema.__$refResolved && currentSchema.__$refResolved !== currentSchema && merge(recurse(currentSchema.__$refResolved))) return "all";
|
|
4423
4450
|
const recursiveTarget = resolveRecursiveRef(currentSchema, report.__$recursiveAnchorStack);
|
|
4424
|
-
if (recursiveTarget && recursiveTarget !== currentSchema)
|
|
4425
|
-
if (merge(recurse(recursiveTarget))) return "all";
|
|
4426
|
-
}
|
|
4451
|
+
if (recursiveTarget && recursiveTarget !== currentSchema && merge(recurse(recursiveTarget))) return "all";
|
|
4427
4452
|
const dynamicTarget = resolveDynamicRef(currentSchema, report.__$dynamicScopeStack);
|
|
4428
|
-
if (dynamicTarget && dynamicTarget !== currentSchema)
|
|
4429
|
-
if (merge(recurse(dynamicTarget))) return "all";
|
|
4430
|
-
}
|
|
4453
|
+
if (dynamicTarget && dynamicTarget !== currentSchema && merge(recurse(dynamicTarget))) return "all";
|
|
4431
4454
|
return evaluated;
|
|
4432
4455
|
}
|
|
4433
|
-
function unevaluatedItemsValidator(report, schema, json) {
|
|
4456
|
+
function unevaluatedItemsValidator(ctx, report, schema, json) {
|
|
4434
4457
|
if (!Array.isArray(json)) return;
|
|
4435
4458
|
if (schema.unevaluatedItems === true) return;
|
|
4436
4459
|
const unevalSchema = schema.unevaluatedItems;
|
|
4437
4460
|
if (unevalSchema === void 0) return;
|
|
4438
4461
|
if (json.length === 0) return;
|
|
4439
|
-
const evaluatedItems = collectEvaluated
|
|
4462
|
+
const evaluatedItems = collectEvaluated(ctx, {
|
|
4440
4463
|
report,
|
|
4441
4464
|
currentSchema: schema,
|
|
4442
4465
|
json,
|
|
@@ -4449,23 +4472,24 @@
|
|
|
4449
4472
|
for (let i = 0; i < json.length; i++) if (!evaluatedItems.has(i)) unevaluatedIndices.push(i);
|
|
4450
4473
|
if (unevaluatedIndices.length === 0) return;
|
|
4451
4474
|
if (unevalSchema === false) report.addError("ARRAY_UNEVALUATED_ITEMS", void 0, void 0, schema, "unevaluatedItems");
|
|
4452
|
-
else for (
|
|
4475
|
+
else for (let i = 0; i < unevaluatedIndices.length; i++) {
|
|
4476
|
+
const idx = unevaluatedIndices[i];
|
|
4453
4477
|
const subReport = new Report(report);
|
|
4454
|
-
validate
|
|
4478
|
+
validate(ctx, subReport, unevalSchema, json[idx]);
|
|
4455
4479
|
if (subReport.errors.length > 0) {
|
|
4456
4480
|
report.addError("ARRAY_UNEVALUATED_ITEMS", void 0, void 0, schema, "unevaluatedItems");
|
|
4457
4481
|
break;
|
|
4458
4482
|
}
|
|
4459
4483
|
}
|
|
4460
4484
|
}
|
|
4461
|
-
function unevaluatedPropertiesValidator(report, schema, json) {
|
|
4485
|
+
function unevaluatedPropertiesValidator(ctx, report, schema, json) {
|
|
4462
4486
|
if (!isObject(json)) return;
|
|
4463
4487
|
if (schema.unevaluatedProperties === true) return;
|
|
4464
4488
|
const unevalSchema = schema.unevaluatedProperties;
|
|
4465
4489
|
if (unevalSchema === void 0) return;
|
|
4466
4490
|
const allKeys = Object.keys(json);
|
|
4467
4491
|
if (allKeys.length === 0) return;
|
|
4468
|
-
const evaluatedProperties = collectEvaluated
|
|
4492
|
+
const evaluatedProperties = collectEvaluated(ctx, {
|
|
4469
4493
|
report,
|
|
4470
4494
|
currentSchema: schema,
|
|
4471
4495
|
json,
|
|
@@ -4474,32 +4498,35 @@
|
|
|
4474
4498
|
depth: 0
|
|
4475
4499
|
});
|
|
4476
4500
|
if (evaluatedProperties === "all") return;
|
|
4477
|
-
const unevaluatedKeys =
|
|
4501
|
+
const unevaluatedKeys = [];
|
|
4502
|
+
for (let i = 0; i < allKeys.length; i++) if (!evaluatedProperties.has(allKeys[i])) unevaluatedKeys.push(allKeys[i]);
|
|
4478
4503
|
if (unevaluatedKeys.length === 0) return;
|
|
4479
4504
|
if (unevalSchema === false) report.addError("OBJECT_UNEVALUATED_PROPERTIES", [unevaluatedKeys.join(", ")], void 0, schema, "unevaluatedProperties");
|
|
4480
|
-
else for (
|
|
4505
|
+
else for (let i = 0; i < unevaluatedKeys.length; i++) {
|
|
4506
|
+
const key = unevaluatedKeys[i];
|
|
4481
4507
|
const subReport = new Report(report);
|
|
4482
|
-
validate
|
|
4508
|
+
validate(ctx, subReport, unevalSchema, json[key]);
|
|
4483
4509
|
if (subReport.errors.length > 0) report.addError("OBJECT_UNEVALUATED_PROPERTIES", [key], void 0, schema, "unevaluatedProperties");
|
|
4484
4510
|
}
|
|
4485
4511
|
}
|
|
4486
4512
|
function definitionsValidator() {}
|
|
4513
|
+
const noopValidator = () => {};
|
|
4487
4514
|
const JsonValidators = {
|
|
4488
|
-
id:
|
|
4489
|
-
$id:
|
|
4490
|
-
$ref:
|
|
4491
|
-
$schema:
|
|
4492
|
-
$dynamicAnchor:
|
|
4493
|
-
$dynamicRef:
|
|
4494
|
-
$anchor:
|
|
4495
|
-
$defs:
|
|
4496
|
-
$vocabulary:
|
|
4497
|
-
$recursiveAnchor:
|
|
4498
|
-
$recursiveRef:
|
|
4499
|
-
examples:
|
|
4500
|
-
title:
|
|
4501
|
-
description:
|
|
4502
|
-
default:
|
|
4515
|
+
id: noopValidator,
|
|
4516
|
+
$id: noopValidator,
|
|
4517
|
+
$ref: noopValidator,
|
|
4518
|
+
$schema: noopValidator,
|
|
4519
|
+
$dynamicAnchor: noopValidator,
|
|
4520
|
+
$dynamicRef: noopValidator,
|
|
4521
|
+
$anchor: noopValidator,
|
|
4522
|
+
$defs: noopValidator,
|
|
4523
|
+
$vocabulary: noopValidator,
|
|
4524
|
+
$recursiveAnchor: noopValidator,
|
|
4525
|
+
$recursiveRef: noopValidator,
|
|
4526
|
+
examples: noopValidator,
|
|
4527
|
+
title: noopValidator,
|
|
4528
|
+
description: noopValidator,
|
|
4529
|
+
default: noopValidator,
|
|
4503
4530
|
type: typeValidator,
|
|
4504
4531
|
enum: enumValidator,
|
|
4505
4532
|
const: constValidator,
|
|
@@ -4544,18 +4571,18 @@
|
|
|
4544
4571
|
else: elseValidator,
|
|
4545
4572
|
definitions: definitionsValidator
|
|
4546
4573
|
};
|
|
4547
|
-
|
|
4574
|
+
function recurseArray(ctx, report, schema, json) {
|
|
4548
4575
|
const schemaUri = typeof schema.$schema === "string" ? schema.$schema : void 0;
|
|
4549
|
-
const prefixItems = (schemaUri === "https://json-schema.org/draft/2020-12/schema" || !schemaUri &&
|
|
4576
|
+
const prefixItems = (schemaUri === "https://json-schema.org/draft/2020-12/schema" || !schemaUri && ctx.options.version === "draft2020-12") && Array.isArray(schema.prefixItems) ? schema.prefixItems : void 0;
|
|
4550
4577
|
if (prefixItems) {
|
|
4551
4578
|
for (let idx = 0; idx < json.length; idx++) if (idx < prefixItems.length) {
|
|
4552
4579
|
report.path.push(idx);
|
|
4553
|
-
validate
|
|
4580
|
+
validate(ctx, report, prefixItems[idx], json[idx]);
|
|
4554
4581
|
report.path.pop();
|
|
4555
4582
|
} else if (schema.items !== void 0 && !Array.isArray(schema.items)) {
|
|
4556
4583
|
report.path.push(idx);
|
|
4557
4584
|
report.schemaPath.push("items");
|
|
4558
|
-
validate
|
|
4585
|
+
validate(ctx, report, schema.items, json[idx]);
|
|
4559
4586
|
report.schemaPath.pop();
|
|
4560
4587
|
report.path.pop();
|
|
4561
4588
|
}
|
|
@@ -4564,50 +4591,56 @@
|
|
|
4564
4591
|
if (Array.isArray(schema.items)) {
|
|
4565
4592
|
for (let idx = 0; idx < json.length; idx++) if (idx < schema.items.length) {
|
|
4566
4593
|
report.path.push(idx);
|
|
4567
|
-
validate
|
|
4594
|
+
validate(ctx, report, schema.items[idx], json[idx]);
|
|
4568
4595
|
report.path.pop();
|
|
4569
4596
|
} else if (typeof schema.additionalItems === "object") {
|
|
4570
4597
|
report.path.push(idx);
|
|
4571
|
-
validate
|
|
4598
|
+
validate(ctx, report, schema.additionalItems, json[idx]);
|
|
4572
4599
|
report.path.pop();
|
|
4573
4600
|
}
|
|
4574
4601
|
} else if (typeof schema.items === "object" || typeof schema.items === "boolean") for (let idx = 0; idx < json.length; idx++) {
|
|
4575
4602
|
report.path.push(idx);
|
|
4576
4603
|
report.schemaPath.push("items");
|
|
4577
|
-
validate
|
|
4604
|
+
validate(ctx, report, schema.items, json[idx]);
|
|
4578
4605
|
report.schemaPath.pop();
|
|
4579
4606
|
report.path.pop();
|
|
4580
4607
|
}
|
|
4581
|
-
}
|
|
4582
|
-
|
|
4583
|
-
let additionalProperties = schema
|
|
4608
|
+
}
|
|
4609
|
+
function recurseObject(ctx, report, schema, json) {
|
|
4610
|
+
let { additionalProperties } = schema;
|
|
4584
4611
|
if (additionalProperties === true || additionalProperties === void 0) additionalProperties = {};
|
|
4585
4612
|
const p = schema.properties ? Object.keys(schema.properties) : [];
|
|
4586
4613
|
const pp = schema.patternProperties ? Object.keys(schema.patternProperties) : [];
|
|
4587
4614
|
const keys = Object.keys(json);
|
|
4615
|
+
const ppCompiled = [];
|
|
4616
|
+
for (let i = 0; i < pp.length; i++) {
|
|
4617
|
+
const r = compileSchemaRegex(pp[i]);
|
|
4618
|
+
if (r.ok) ppCompiled.push({
|
|
4619
|
+
key: pp[i],
|
|
4620
|
+
re: r.value
|
|
4621
|
+
});
|
|
4622
|
+
}
|
|
4588
4623
|
for (const m of keys) {
|
|
4589
4624
|
const propertyValue = json[m];
|
|
4625
|
+
const isProp = p.includes(m);
|
|
4590
4626
|
const s = [];
|
|
4591
|
-
if (
|
|
4592
|
-
for (
|
|
4593
|
-
const result = compileSchemaRegex(regexString);
|
|
4594
|
-
if (result.ok && result.value.test(m) === true) s.push(schema.patternProperties[regexString]);
|
|
4595
|
-
}
|
|
4627
|
+
if (isProp) s.push(schema.properties[m]);
|
|
4628
|
+
for (let i = 0; i < ppCompiled.length; i++) if (ppCompiled[i].re.test(m)) s.push(schema.patternProperties[ppCompiled[i].key]);
|
|
4596
4629
|
if (s.length === 0 && additionalProperties !== false) s.push(additionalProperties);
|
|
4597
4630
|
for (const schema_s of s) {
|
|
4598
4631
|
report.path.push(m);
|
|
4599
|
-
if (
|
|
4632
|
+
if (isProp) {
|
|
4600
4633
|
report.schemaPath.push("properties");
|
|
4601
4634
|
report.schemaPath.push(m);
|
|
4602
4635
|
} else report.schemaPath.push("additionalProperties");
|
|
4603
|
-
validate
|
|
4636
|
+
validate(ctx, report, schema_s, propertyValue);
|
|
4604
4637
|
report.path.pop();
|
|
4605
4638
|
report.schemaPath.pop();
|
|
4606
|
-
if (
|
|
4639
|
+
if (isProp) report.schemaPath.pop();
|
|
4607
4640
|
}
|
|
4608
4641
|
}
|
|
4609
|
-
}
|
|
4610
|
-
function validate(report, schema, json) {
|
|
4642
|
+
}
|
|
4643
|
+
function validate(ctx, report, schema, json) {
|
|
4611
4644
|
report.commonErrorMessage = "JSON_OBJECT_VALIDATION_FAILED";
|
|
4612
4645
|
if (schema === true) return true;
|
|
4613
4646
|
if (schema === false) {
|
|
@@ -4631,7 +4664,7 @@
|
|
|
4631
4664
|
let pushedDynamicScope = false;
|
|
4632
4665
|
const schemaId = getId(schema);
|
|
4633
4666
|
const dynamicScopeEntry = schema.__$resourceRoot || (isRoot || typeof schemaId === "string" ? schema : void 0);
|
|
4634
|
-
if (dynamicScopeEntry && dynamicScopeStack
|
|
4667
|
+
if (dynamicScopeEntry && dynamicScopeStack.at(-1) !== dynamicScopeEntry) {
|
|
4635
4668
|
dynamicScopeStack.push(dynamicScopeEntry);
|
|
4636
4669
|
pushedDynamicScope = true;
|
|
4637
4670
|
}
|
|
@@ -4639,10 +4672,11 @@
|
|
|
4639
4672
|
recursiveAnchorStack.push(schema);
|
|
4640
4673
|
pushedRecursiveAnchor = true;
|
|
4641
4674
|
}
|
|
4642
|
-
if (schema.$ref !== void 0) if (
|
|
4643
|
-
if (
|
|
4644
|
-
else
|
|
4645
|
-
|
|
4675
|
+
if (schema.$ref !== void 0) if (ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12") {
|
|
4676
|
+
if (schema.__$refResolved) validate(ctx, report, schema.__$refResolved, json);
|
|
4677
|
+
else report.addError("REF_UNRESOLVED", [schema.$ref], void 0, schema);
|
|
4678
|
+
const refIdx = keys.indexOf("$ref");
|
|
4679
|
+
if (refIdx !== -1) keys.splice(refIdx, 1);
|
|
4646
4680
|
} else {
|
|
4647
4681
|
let maxRefs = 99;
|
|
4648
4682
|
while (schema.$ref && maxRefs > 0) {
|
|
@@ -4660,58 +4694,65 @@
|
|
|
4660
4694
|
report.schemaPath = [];
|
|
4661
4695
|
}
|
|
4662
4696
|
if (schema.$recursiveRef !== void 0) {
|
|
4663
|
-
if (
|
|
4697
|
+
if (ctx.options.version === "draft2019-09" || ctx.options.version === "draft2020-12") {
|
|
4664
4698
|
const recursiveRefTarget = resolveRecursiveRef(schema, recursiveAnchorStack);
|
|
4665
|
-
if (
|
|
4666
|
-
else
|
|
4667
|
-
|
|
4699
|
+
if (recursiveRefTarget) validate(ctx, report, recursiveRefTarget, json);
|
|
4700
|
+
else report.addError("REF_UNRESOLVED", [schema.$recursiveRef], void 0, schema);
|
|
4701
|
+
const recursiveRefIdx = keys.indexOf("$recursiveRef");
|
|
4702
|
+
if (recursiveRefIdx !== -1) keys.splice(recursiveRefIdx, 1);
|
|
4668
4703
|
}
|
|
4669
4704
|
}
|
|
4670
4705
|
if (schema.$dynamicRef !== void 0) {
|
|
4671
|
-
if (
|
|
4706
|
+
if (ctx.options.version === "draft2020-12") {
|
|
4672
4707
|
const dynamicRefTarget = resolveDynamicRef(schema, dynamicScopeStack);
|
|
4673
|
-
if (
|
|
4674
|
-
else validate
|
|
4675
|
-
|
|
4708
|
+
if (dynamicRefTarget === void 0) report.addError("REF_UNRESOLVED", [schema.$dynamicRef], void 0, schema);
|
|
4709
|
+
else validate(ctx, report, dynamicRefTarget, json);
|
|
4710
|
+
const dynamicRefIdx = keys.indexOf("$dynamicRef");
|
|
4711
|
+
if (dynamicRefIdx !== -1) keys.splice(dynamicRefIdx, 1);
|
|
4676
4712
|
}
|
|
4677
4713
|
}
|
|
4678
|
-
const validationVocabularyEnabled = isValidationVocabularyEnabled(schema, report,
|
|
4679
|
-
if (!validationVocabularyEnabled)
|
|
4714
|
+
const validationVocabularyEnabled = isValidationVocabularyEnabled(schema, report, ctx.options.version);
|
|
4715
|
+
if (!validationVocabularyEnabled) {
|
|
4716
|
+
let wi = 0;
|
|
4717
|
+
for (let ri = 0; ri < keys.length; ri++) if (!VALIDATION_VOCAB_KEYWORDS.has(keys[ri])) keys[wi++] = keys[ri];
|
|
4718
|
+
keys.length = wi;
|
|
4719
|
+
}
|
|
4680
4720
|
if (validationVocabularyEnabled && schema.type) {
|
|
4681
4721
|
keys.splice(keys.indexOf("type"), 1);
|
|
4682
4722
|
report.schemaPath.push("type");
|
|
4683
|
-
JsonValidators.type
|
|
4723
|
+
JsonValidators.type(ctx, report, schema, json);
|
|
4684
4724
|
report.schemaPath.pop();
|
|
4685
|
-
if (report.errors.length &&
|
|
4725
|
+
if (report.errors.length && ctx.options.breakOnFirstError) {
|
|
4686
4726
|
if (pushedRecursiveAnchor) recursiveAnchorStack.pop();
|
|
4687
4727
|
if (pushedDynamicScope) dynamicScopeStack.pop();
|
|
4688
4728
|
return false;
|
|
4689
4729
|
}
|
|
4690
4730
|
}
|
|
4691
4731
|
const deferredUnevaluatedKeys = [];
|
|
4692
|
-
for (
|
|
4732
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4733
|
+
const key = keys[i];
|
|
4693
4734
|
if (key === "unevaluatedItems" || key === "unevaluatedProperties") {
|
|
4694
4735
|
deferredUnevaluatedKeys.push(key);
|
|
4695
4736
|
continue;
|
|
4696
4737
|
}
|
|
4697
4738
|
const validator = JsonValidators[key];
|
|
4698
4739
|
if (validator) {
|
|
4699
|
-
validator
|
|
4700
|
-
if (report.errors.length &&
|
|
4740
|
+
validator(ctx, report, schema, json);
|
|
4741
|
+
if (report.errors.length && ctx.options.breakOnFirstError) break;
|
|
4701
4742
|
}
|
|
4702
4743
|
}
|
|
4703
|
-
if (deferredUnevaluatedKeys.length > 0 && !(report.errors.length > 0 &&
|
|
4704
|
-
const validator = JsonValidators[
|
|
4744
|
+
if (deferredUnevaluatedKeys.length > 0 && !(report.errors.length > 0 && ctx.options.breakOnFirstError)) for (let i = 0; i < deferredUnevaluatedKeys.length; i++) {
|
|
4745
|
+
const validator = JsonValidators[deferredUnevaluatedKeys[i]];
|
|
4705
4746
|
if (validator) {
|
|
4706
|
-
validator
|
|
4707
|
-
if (report.errors.length &&
|
|
4747
|
+
validator(ctx, report, schema, json);
|
|
4748
|
+
if (report.errors.length && ctx.options.breakOnFirstError) break;
|
|
4708
4749
|
}
|
|
4709
4750
|
}
|
|
4710
|
-
if (report.errors.length === 0 ||
|
|
4711
|
-
if (Array.isArray(json)) recurseArray
|
|
4712
|
-
else if (isObject(json)) recurseObject
|
|
4751
|
+
if (report.errors.length === 0 || ctx.options.breakOnFirstError === false) {
|
|
4752
|
+
if (Array.isArray(json)) recurseArray(ctx, report, schema, json);
|
|
4753
|
+
else if (isObject(json)) recurseObject(ctx, report, schema, json);
|
|
4713
4754
|
}
|
|
4714
|
-
if (typeof
|
|
4755
|
+
if (typeof ctx.options.customValidator === "function") ctx.options.customValidator.call(ctx, report, schema, json);
|
|
4715
4756
|
if (pushedRecursiveAnchor) recursiveAnchorStack.pop();
|
|
4716
4757
|
if (pushedDynamicScope) dynamicScopeStack.pop();
|
|
4717
4758
|
if (isRoot) report.rootSchema = void 0;
|
|
@@ -4728,14 +4769,14 @@
|
|
|
4728
4769
|
}
|
|
4729
4770
|
//#endregion
|
|
4730
4771
|
//#region src/schema-compiler.ts
|
|
4731
|
-
const UNSAFE_TARGETS = [
|
|
4772
|
+
const UNSAFE_TARGETS = new Set([
|
|
4732
4773
|
Object.prototype,
|
|
4733
4774
|
Function.prototype,
|
|
4734
4775
|
Array.prototype
|
|
4735
|
-
];
|
|
4776
|
+
]);
|
|
4736
4777
|
/** Returns true if `obj` is a built-in prototype that must not be mutated. */
|
|
4737
4778
|
function isUnsafeTarget(obj) {
|
|
4738
|
-
return UNSAFE_TARGETS.
|
|
4779
|
+
return UNSAFE_TARGETS.has(obj);
|
|
4739
4780
|
}
|
|
4740
4781
|
/** Safely assign a property on `obj`, refusing prototype-polluting keys. */
|
|
4741
4782
|
function safeSetProperty(obj, key, value) {
|
|
@@ -4748,35 +4789,78 @@
|
|
|
4748
4789
|
if (isUnsafeTarget(obj)) return;
|
|
4749
4790
|
if (key !== "__proto__" && key !== "constructor" && key !== "prototype") delete obj[key];
|
|
4750
4791
|
}
|
|
4792
|
+
const resolveReference = (base, ref) => {
|
|
4793
|
+
if (isAbsoluteUri(ref)) return ref;
|
|
4794
|
+
const baseStr = base ?? "";
|
|
4795
|
+
if (ref.startsWith("#")) {
|
|
4796
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4797
|
+
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + ref;
|
|
4798
|
+
}
|
|
4799
|
+
if (!baseStr) return ref;
|
|
4800
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4801
|
+
const baseNoFrag = hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex);
|
|
4802
|
+
if (isAbsoluteUri(baseNoFrag)) try {
|
|
4803
|
+
return new URL(ref, baseNoFrag).toString();
|
|
4804
|
+
} catch {}
|
|
4805
|
+
let baseDir = baseNoFrag;
|
|
4806
|
+
if (!baseDir.endsWith("/")) {
|
|
4807
|
+
const lastSlash = baseDir.lastIndexOf("/");
|
|
4808
|
+
baseDir = lastSlash === -1 ? "" : baseDir.slice(0, lastSlash + 1);
|
|
4809
|
+
}
|
|
4810
|
+
return baseDir + ref;
|
|
4811
|
+
};
|
|
4812
|
+
const isSimpleIdentifier = (id) => !id.startsWith("#") && !id.includes("/") && !id.includes(".") && !id.includes("#");
|
|
4813
|
+
const resolveIdScope = (base, id) => {
|
|
4814
|
+
if (isAbsoluteUri(id)) return id;
|
|
4815
|
+
const baseStr = base ?? "";
|
|
4816
|
+
if (isSimpleIdentifier(id)) {
|
|
4817
|
+
const hashIndex = baseStr.indexOf("#");
|
|
4818
|
+
return `${hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)}#${id}`;
|
|
4819
|
+
}
|
|
4820
|
+
return resolveReference(base, id);
|
|
4821
|
+
};
|
|
4822
|
+
const resolveSchemaScopeId = (base, schema, id) => {
|
|
4823
|
+
if (typeof schema.$id === "string") return resolveReference(base, id);
|
|
4824
|
+
return resolveIdScope(base, id);
|
|
4825
|
+
};
|
|
4751
4826
|
const collectIds = (obj, maxDepth = 100) => {
|
|
4752
4827
|
const ids = [];
|
|
4753
4828
|
function walk(node, scope, _depth = 0) {
|
|
4754
4829
|
if (typeof node !== "object" || node == null) return;
|
|
4830
|
+
const schemaNode = node;
|
|
4755
4831
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in collectIds. If your schema is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
4756
4832
|
let addedScope = false;
|
|
4757
|
-
const nodeId = getId(
|
|
4833
|
+
const nodeId = getId(schemaNode);
|
|
4758
4834
|
if (typeof nodeId === "string") {
|
|
4759
4835
|
let type = isAbsoluteUri(nodeId) ? "absolute" : "relative";
|
|
4760
4836
|
if (scope.length === 0) type = "root";
|
|
4761
4837
|
const id = {
|
|
4762
4838
|
id: nodeId,
|
|
4763
4839
|
type,
|
|
4764
|
-
obj:
|
|
4840
|
+
obj: schemaNode
|
|
4765
4841
|
};
|
|
4766
4842
|
if (type === "absolute" || type === "root" && isAbsoluteUri(nodeId)) id.absoluteUri = nodeId;
|
|
4767
|
-
else if (type === "root" && typeof
|
|
4843
|
+
else if (type === "root" && typeof schemaNode.id === "string" && isAbsoluteUri(schemaNode.id) && schemaNode.id !== nodeId) id.absoluteUri = resolveSchemaScopeId(schemaNode.id, schemaNode, nodeId);
|
|
4768
4844
|
else if (type === "relative") {
|
|
4769
|
-
|
|
4770
|
-
|
|
4845
|
+
let absoluteParent;
|
|
4846
|
+
for (let i = scope.length - 1; i >= 0; i--) {
|
|
4847
|
+
const sc = scope[i];
|
|
4848
|
+
if (sc.type === "absolute" || sc.type === "root" && sc.absoluteUri) {
|
|
4849
|
+
absoluteParent = sc;
|
|
4850
|
+
break;
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
id.absoluteParent = absoluteParent;
|
|
4854
|
+
if (id.absoluteParent) id.absoluteUri = resolveSchemaScopeId(id.absoluteParent.absoluteUri || id.absoluteParent.id, schemaNode, id.id);
|
|
4771
4855
|
}
|
|
4772
4856
|
ids.push(id);
|
|
4773
4857
|
scope.push(id);
|
|
4774
4858
|
addedScope = true;
|
|
4775
4859
|
}
|
|
4776
4860
|
if (Array.isArray(node)) for (const item of node) walk(item, scope, _depth + 1);
|
|
4777
|
-
else for (const key of Object.keys(
|
|
4778
|
-
if (isInternalKey(key) ||
|
|
4779
|
-
walk(
|
|
4861
|
+
else for (const key of Object.keys(schemaNode)) {
|
|
4862
|
+
if (isInternalKey(key) || NON_SCHEMA_KEYWORDS_SET.has(key)) continue;
|
|
4863
|
+
walk(schemaNode[key], scope, _depth + 1);
|
|
4780
4864
|
}
|
|
4781
4865
|
if (addedScope) scope.pop();
|
|
4782
4866
|
}
|
|
@@ -4784,42 +4868,42 @@
|
|
|
4784
4868
|
return ids;
|
|
4785
4869
|
};
|
|
4786
4870
|
const collectReferences = (obj, results, scope, path, options, maxDepth = 100, _depth = 0) => {
|
|
4787
|
-
results
|
|
4788
|
-
scope
|
|
4789
|
-
path
|
|
4790
|
-
options
|
|
4871
|
+
results ||= [];
|
|
4872
|
+
scope ||= [];
|
|
4873
|
+
path ||= [];
|
|
4874
|
+
options ||= {};
|
|
4791
4875
|
if (typeof obj !== "object" || obj === null) return results;
|
|
4792
4876
|
if (_depth >= maxDepth) throw new Error(`Maximum recursion depth (${maxDepth}) exceeded in collectReferences. If your schema is deeply nested and valid, increase the maxRecursionDepth option.`);
|
|
4793
|
-
const hasRef = typeof obj.$ref === "string" &&
|
|
4877
|
+
const hasRef = typeof obj.$ref === "string" && obj.__$refResolved === void 0;
|
|
4794
4878
|
let addedScope = false;
|
|
4795
4879
|
const isRootScope = scope.length === 0;
|
|
4796
4880
|
let scopeId = getId(obj);
|
|
4797
4881
|
if (typeof obj.id === "string" && isAbsoluteUri(obj.id) && (!scopeId || !isAbsoluteUri(scopeId))) scopeId = obj.id;
|
|
4798
4882
|
if (typeof scopeId === "string" && (isRootScope || !hasRef || options.useRefObjectScope === true)) {
|
|
4799
|
-
const base = scope.length > 0 ? scope
|
|
4883
|
+
const base = scope.length > 0 ? scope.at(-1) : void 0;
|
|
4800
4884
|
scope.push(resolveSchemaScopeId(base, obj, scopeId));
|
|
4801
4885
|
addedScope = true;
|
|
4802
4886
|
}
|
|
4803
4887
|
if (hasRef) results.push({
|
|
4804
|
-
ref: resolveReference(scope
|
|
4888
|
+
ref: resolveReference(scope.at(-1), obj.$ref),
|
|
4805
4889
|
key: "$ref",
|
|
4806
4890
|
obj,
|
|
4807
4891
|
path: path.slice(0)
|
|
4808
4892
|
});
|
|
4809
|
-
if (typeof obj.$recursiveRef === "string" &&
|
|
4810
|
-
ref: resolveReference(scope
|
|
4893
|
+
if (typeof obj.$recursiveRef === "string" && obj.__$recursiveRefResolved === void 0) results.push({
|
|
4894
|
+
ref: resolveReference(scope.at(-1), obj.$recursiveRef),
|
|
4811
4895
|
key: "$recursiveRef",
|
|
4812
4896
|
obj,
|
|
4813
4897
|
path: path.slice(0)
|
|
4814
4898
|
});
|
|
4815
|
-
if (typeof obj.$dynamicRef === "string" &&
|
|
4816
|
-
ref: resolveReference(scope
|
|
4899
|
+
if (typeof obj.$dynamicRef === "string" && obj.__$dynamicRefResolved === void 0) results.push({
|
|
4900
|
+
ref: resolveReference(scope.at(-1), obj.$dynamicRef),
|
|
4817
4901
|
key: "$dynamicRef",
|
|
4818
4902
|
obj,
|
|
4819
4903
|
path: path.slice(0)
|
|
4820
4904
|
});
|
|
4821
|
-
if (typeof obj.$schema === "string" &&
|
|
4822
|
-
ref: resolveReference(scope
|
|
4905
|
+
if (typeof obj.$schema === "string" && obj.__$schemaResolved === void 0) results.push({
|
|
4906
|
+
ref: resolveReference(scope.at(-1), obj.$schema),
|
|
4823
4907
|
key: "$schema",
|
|
4824
4908
|
obj,
|
|
4825
4909
|
path: path.slice(0)
|
|
@@ -4832,7 +4916,7 @@
|
|
|
4832
4916
|
else {
|
|
4833
4917
|
const keys = Object.keys(obj);
|
|
4834
4918
|
for (const key of keys) {
|
|
4835
|
-
if (isInternalKey(key) ||
|
|
4919
|
+
if (isInternalKey(key) || NON_SCHEMA_KEYWORDS_SET.has(key)) continue;
|
|
4836
4920
|
path.push(key);
|
|
4837
4921
|
collectReferences(obj[key], results, scope, path, options, maxDepth, _depth + 1);
|
|
4838
4922
|
path.pop();
|
|
@@ -4841,41 +4925,8 @@
|
|
|
4841
4925
|
if (addedScope) scope.pop();
|
|
4842
4926
|
return results;
|
|
4843
4927
|
};
|
|
4844
|
-
const resolveReference = (base, ref) => {
|
|
4845
|
-
if (isAbsoluteUri(ref)) return ref;
|
|
4846
|
-
const baseStr = base ?? "";
|
|
4847
|
-
if (ref[0] === "#") {
|
|
4848
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4849
|
-
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + ref;
|
|
4850
|
-
}
|
|
4851
|
-
if (!baseStr) return ref;
|
|
4852
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4853
|
-
const baseNoFrag = hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex);
|
|
4854
|
-
if (isAbsoluteUri(baseNoFrag)) try {
|
|
4855
|
-
return new URL(ref, baseNoFrag).toString();
|
|
4856
|
-
} catch {}
|
|
4857
|
-
let baseDir = baseNoFrag;
|
|
4858
|
-
if (!baseDir.endsWith("/")) {
|
|
4859
|
-
const lastSlash = baseDir.lastIndexOf("/");
|
|
4860
|
-
baseDir = lastSlash === -1 ? "" : baseDir.slice(0, lastSlash + 1);
|
|
4861
|
-
}
|
|
4862
|
-
return baseDir + ref;
|
|
4863
|
-
};
|
|
4864
|
-
const isSimpleIdentifier = (id) => id[0] !== "#" && !id.includes("/") && !id.includes(".") && !id.includes("#");
|
|
4865
|
-
const resolveIdScope = (base, id) => {
|
|
4866
|
-
if (isAbsoluteUri(id)) return id;
|
|
4867
|
-
const baseStr = base ?? "";
|
|
4868
|
-
if (isSimpleIdentifier(id)) {
|
|
4869
|
-
const hashIndex = baseStr.indexOf("#");
|
|
4870
|
-
return (hashIndex === -1 ? baseStr : baseStr.slice(0, hashIndex)) + "#" + id;
|
|
4871
|
-
}
|
|
4872
|
-
return resolveReference(base, id);
|
|
4873
|
-
};
|
|
4874
|
-
const resolveSchemaScopeId = (base, schema, id) => {
|
|
4875
|
-
if (typeof schema.$id === "string") return resolveReference(base, id);
|
|
4876
|
-
return resolveIdScope(base, id);
|
|
4877
|
-
};
|
|
4878
4928
|
var SchemaCompiler = class {
|
|
4929
|
+
validator;
|
|
4879
4930
|
constructor(validator) {
|
|
4880
4931
|
this.validator = validator;
|
|
4881
4932
|
}
|
|
@@ -4893,19 +4944,19 @@
|
|
|
4893
4944
|
report.commonErrorMessage = "SCHEMA_COMPILATION_FAILED";
|
|
4894
4945
|
if (typeof schema === "string") {
|
|
4895
4946
|
const loadedSchema = this.validator.scache.getSchemaByUri(report, schema);
|
|
4896
|
-
if (
|
|
4947
|
+
if (loadedSchema === void 0) {
|
|
4897
4948
|
report.addError("SCHEMA_NOT_REACHABLE", [schema]);
|
|
4898
4949
|
return false;
|
|
4899
4950
|
}
|
|
4900
4951
|
schema = loadedSchema;
|
|
4901
4952
|
}
|
|
4902
4953
|
if (Array.isArray(schema)) {
|
|
4903
|
-
if (!options?.noCache) schema.
|
|
4954
|
+
if (!options?.noCache) for (let i = 0; i < schema.length; i++) this.collectAndCacheIds(schema[i]);
|
|
4904
4955
|
return this.compileArrayOfSchemas(report, schema);
|
|
4905
4956
|
} else if (typeof schema === "boolean") return true;
|
|
4906
|
-
|
|
4957
|
+
if (!options?.noCache) this.collectAndCacheIds(schema);
|
|
4907
4958
|
const canMutateSchemaObject = schema !== Object.prototype && schema !== Function.prototype && schema !== Array.prototype;
|
|
4908
|
-
if (canMutateSchemaObject && schema.__$compiled && schema.id && this.validator.scache.checkCacheForUri(schema.id)
|
|
4959
|
+
if (canMutateSchemaObject && schema.__$compiled && schema.id && !this.validator.scache.checkCacheForUri(schema.id)) schema.__$compiled = void 0;
|
|
4909
4960
|
if (schema.__$compiled) return true;
|
|
4910
4961
|
if (canMutateSchemaObject && !schema.$schema && this.validator.options.version !== "none") schema.$schema = this.validator.getDefaultSchemaId();
|
|
4911
4962
|
if (schema.id && typeof schema.id === "string" && !options?.noCache) this.validator.scache.cacheSchemaByUri(schema.id, schema);
|
|
@@ -4920,7 +4971,7 @@
|
|
|
4920
4971
|
const refs = collectReferences(schema, void 0, void 0, void 0, { useRefObjectScope }, this.validator.options.maxRecursionDepth);
|
|
4921
4972
|
for (const refObj of refs) {
|
|
4922
4973
|
let response = this.validator.scache.getSchemaByUri(report, refObj.ref, schema);
|
|
4923
|
-
if (
|
|
4974
|
+
if (response === void 0) {
|
|
4924
4975
|
const schemaReader = getSchemaReader();
|
|
4925
4976
|
if (schemaReader) {
|
|
4926
4977
|
const remotePath = getRemotePath(refObj.ref);
|
|
@@ -4928,23 +4979,24 @@
|
|
|
4928
4979
|
if (s) {
|
|
4929
4980
|
s.id = remotePath;
|
|
4930
4981
|
const subreport = new Report(report);
|
|
4931
|
-
if (
|
|
4932
|
-
else
|
|
4982
|
+
if (this.compileSchema(subreport, s)) response = this.validator.scache.getSchemaByUri(report, refObj.ref, schema);
|
|
4983
|
+
else for (let i = 0; i < subreport.errors.length; i++) report.errors.push(subreport.errors[i]);
|
|
4933
4984
|
}
|
|
4934
4985
|
}
|
|
4935
4986
|
}
|
|
4936
|
-
if (
|
|
4987
|
+
if (response === void 0) {
|
|
4937
4988
|
const hasNotValid = report.hasError("REMOTE_NOT_VALID", [refObj.ref]);
|
|
4938
4989
|
const isAbsolute = isAbsoluteUri(refObj.ref);
|
|
4939
4990
|
let isDownloaded = false;
|
|
4940
4991
|
const ignoreUnresolvableRemotes = this.validator.options.ignoreUnresolvableReferences === true;
|
|
4941
4992
|
if (isAbsolute) isDownloaded = this.validator.scache.checkCacheForUri(refObj.ref);
|
|
4942
4993
|
if (hasNotValid) {} else if (ignoreUnresolvableRemotes && isAbsolute) {} else if (isDownloaded) {} else {
|
|
4943
|
-
|
|
4994
|
+
const pathLen = refObj.path.length;
|
|
4995
|
+
for (let i = 0; i < pathLen; i++) report.path.push(refObj.path[i]);
|
|
4944
4996
|
report.addError("UNRESOLVABLE_REFERENCE", [refObj.ref]);
|
|
4945
|
-
report.path
|
|
4997
|
+
report.path.length -= pathLen;
|
|
4946
4998
|
if (isValidExceptReferences && canMutateSchemaObject && !isUnsafeTarget(schema)) {
|
|
4947
|
-
schema.__$missingReferences
|
|
4999
|
+
schema.__$missingReferences ||= [];
|
|
4948
5000
|
schema.__$missingReferences.push(refObj);
|
|
4949
5001
|
}
|
|
4950
5002
|
}
|
|
@@ -4959,13 +5011,20 @@
|
|
|
4959
5011
|
compileArrayOfSchemas(report, arr) {
|
|
4960
5012
|
let compiled = 0, lastLoopCompiled;
|
|
4961
5013
|
do {
|
|
4962
|
-
|
|
5014
|
+
let wi = 0;
|
|
5015
|
+
for (let ri = 0; ri < report.errors.length; ri++) if (report.errors[ri].code !== "UNRESOLVABLE_REFERENCE") report.errors[wi++] = report.errors[ri];
|
|
5016
|
+
report.errors.length = wi;
|
|
4963
5017
|
lastLoopCompiled = compiled;
|
|
4964
5018
|
compiled = this.compileArrayOfSchemasLoop(report, arr);
|
|
5019
|
+
const idMap = /* @__PURE__ */ new Map();
|
|
5020
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5021
|
+
const schemaId = arr[i].id;
|
|
5022
|
+
if (schemaId && !idMap.has(schemaId)) idMap.set(schemaId, arr[i]);
|
|
5023
|
+
}
|
|
4965
5024
|
for (const sch of arr) if (sch.__$missingReferences) {
|
|
4966
5025
|
for (let idx2 = sch.__$missingReferences.length - 1; idx2 >= 0; idx2--) {
|
|
4967
5026
|
const refObj = sch.__$missingReferences[idx2];
|
|
4968
|
-
const response =
|
|
5027
|
+
const response = idMap.get(refObj.ref);
|
|
4969
5028
|
if (response) {
|
|
4970
5029
|
safeSetProperty(refObj.obj, `__${refObj.key}Resolved`, response);
|
|
4971
5030
|
sch.__$missingReferences.splice(idx2, 1);
|
|
@@ -4981,62 +5040,74 @@
|
|
|
4981
5040
|
for (const schema of arr) {
|
|
4982
5041
|
const report = new Report(mainReport);
|
|
4983
5042
|
if (this.compileSchema(report, schema)) compiledCount++;
|
|
4984
|
-
|
|
5043
|
+
for (let i = 0; i < report.errors.length; i++) mainReport.errors.push(report.errors[i]);
|
|
4985
5044
|
}
|
|
4986
5045
|
return compiledCount;
|
|
4987
5046
|
}
|
|
4988
5047
|
};
|
|
4989
5048
|
//#endregion
|
|
4990
5049
|
//#region src/schema-validator.ts
|
|
5050
|
+
const PRIMITIVE_TYPES = [
|
|
5051
|
+
"array",
|
|
5052
|
+
"boolean",
|
|
5053
|
+
"integer",
|
|
5054
|
+
"number",
|
|
5055
|
+
"null",
|
|
5056
|
+
"object",
|
|
5057
|
+
"string"
|
|
5058
|
+
];
|
|
5059
|
+
const PRIMITIVE_TYPE_STR = PRIMITIVE_TYPES.join(",");
|
|
5060
|
+
const PRIMITIVE_TYPES_SET = new Set(PRIMITIVE_TYPES);
|
|
4991
5061
|
const SchemaValidators = {
|
|
4992
|
-
$ref
|
|
5062
|
+
$ref(report, schema) {
|
|
4993
5063
|
if (typeof schema.$ref !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["$ref", "string"], void 0, schema, "$ref");
|
|
4994
5064
|
},
|
|
4995
|
-
$schema
|
|
5065
|
+
$schema(report, schema) {
|
|
4996
5066
|
if (typeof schema.$schema !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["$schema", "string"], void 0, schema, "$schema");
|
|
4997
5067
|
},
|
|
4998
|
-
multipleOf
|
|
5068
|
+
multipleOf(report, schema) {
|
|
4999
5069
|
if (typeof schema.multipleOf !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["multipleOf", "number"], void 0, schema, "multipleOf");
|
|
5000
5070
|
else if (schema.multipleOf <= 0) report.addError("KEYWORD_MUST_BE", ["multipleOf", "strictly greater than 0"], void 0, schema, "multipleOf");
|
|
5001
5071
|
},
|
|
5002
|
-
maximum
|
|
5072
|
+
maximum(report, schema) {
|
|
5003
5073
|
if (typeof schema.maximum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["maximum", "number"], void 0, schema, "maximum");
|
|
5004
5074
|
},
|
|
5005
|
-
exclusiveMaximum
|
|
5075
|
+
exclusiveMaximum(report, schema) {
|
|
5006
5076
|
if (report.options.version === "draft-04") {
|
|
5007
5077
|
if (typeof schema.exclusiveMaximum !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMaximum", "boolean"], void 0, schema, "exclusiveMaximum");
|
|
5008
5078
|
else if (schema.maximum === void 0) report.addError("KEYWORD_DEPENDENCY", ["exclusiveMaximum", "maximum"], void 0, schema, "exclusiveMaximum");
|
|
5009
5079
|
} else if (typeof schema.exclusiveMaximum !== "boolean" && typeof schema.exclusiveMaximum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMaximum", ["boolean", "number"]], void 0, schema, "exclusiveMaximum");
|
|
5010
5080
|
},
|
|
5011
|
-
minimum
|
|
5081
|
+
minimum(report, schema) {
|
|
5012
5082
|
if (typeof schema.minimum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["minimum", "number"], void 0, schema, "minimum");
|
|
5013
5083
|
},
|
|
5014
|
-
exclusiveMinimum
|
|
5084
|
+
exclusiveMinimum(report, schema) {
|
|
5015
5085
|
if (report.options.version === "draft-04") {
|
|
5016
5086
|
if (typeof schema.exclusiveMinimum !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMinimum", "boolean"], void 0, schema, "exclusiveMinimum");
|
|
5017
5087
|
else if (schema.minimum === void 0) report.addError("KEYWORD_DEPENDENCY", ["exclusiveMinimum", "minimum"], void 0, schema, "exclusiveMinimum");
|
|
5018
5088
|
} else if (typeof schema.exclusiveMinimum !== "boolean" && typeof schema.exclusiveMinimum !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["exclusiveMinimum", ["boolean", "number"]], void 0, schema, "exclusiveMinimum");
|
|
5019
5089
|
},
|
|
5020
|
-
maxLength
|
|
5090
|
+
maxLength(report, schema) {
|
|
5021
5091
|
if (!isInteger(schema.maxLength)) report.addError("KEYWORD_TYPE_EXPECTED", ["maxLength", "integer"], void 0, schema, "maxLength");
|
|
5022
5092
|
else if (schema.maxLength < 0) report.addError("KEYWORD_MUST_BE", ["maxLength", "greater than, or equal to 0"], void 0, schema, "maxLength");
|
|
5023
5093
|
},
|
|
5024
|
-
minLength
|
|
5094
|
+
minLength(report, schema) {
|
|
5025
5095
|
if (!isInteger(schema.minLength)) report.addError("KEYWORD_TYPE_EXPECTED", ["minLength", "integer"], void 0, schema, "minLength");
|
|
5026
5096
|
else if (schema.minLength < 0) report.addError("KEYWORD_MUST_BE", ["minLength", "greater than, or equal to 0"], void 0, schema, "minLength");
|
|
5027
5097
|
},
|
|
5028
|
-
pattern
|
|
5029
|
-
if (typeof schema.pattern !== "string")
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
if (!result.ok) report.addError("KEYWORD_PATTERN", [
|
|
5033
|
-
"pattern",
|
|
5034
|
-
schema.pattern,
|
|
5035
|
-
result.error.message
|
|
5036
|
-
], void 0, schema, "pattern");
|
|
5098
|
+
pattern(report, schema) {
|
|
5099
|
+
if (typeof schema.pattern !== "string") {
|
|
5100
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["pattern", "string"], void 0, schema, "pattern");
|
|
5101
|
+
return;
|
|
5037
5102
|
}
|
|
5103
|
+
const result = compileSchemaRegex(schema.pattern);
|
|
5104
|
+
if (!result.ok) report.addError("KEYWORD_PATTERN", [
|
|
5105
|
+
"pattern",
|
|
5106
|
+
schema.pattern,
|
|
5107
|
+
result.error.message
|
|
5108
|
+
], void 0, schema, "pattern");
|
|
5038
5109
|
},
|
|
5039
|
-
additionalItems
|
|
5110
|
+
additionalItems(report, schema) {
|
|
5040
5111
|
if (typeof schema.additionalItems !== "boolean" && !isObject(schema.additionalItems)) report.addError("KEYWORD_TYPE_EXPECTED", ["additionalItems", ["boolean", "object"]], void 0, schema, "additionalItems");
|
|
5041
5112
|
else if (isObject(schema.additionalItems)) {
|
|
5042
5113
|
report.path.push("additionalItems");
|
|
@@ -5044,7 +5115,7 @@
|
|
|
5044
5115
|
report.path.pop();
|
|
5045
5116
|
}
|
|
5046
5117
|
},
|
|
5047
|
-
items
|
|
5118
|
+
items(report, schema) {
|
|
5048
5119
|
if (Array.isArray(schema.items)) for (let idx = 0; idx < schema.items.length; idx++) {
|
|
5049
5120
|
report.path.push("items");
|
|
5050
5121
|
report.path.push(idx);
|
|
@@ -5064,34 +5135,34 @@
|
|
|
5064
5135
|
if (this.options.forceAdditional === true && schema.additionalItems === void 0 && Array.isArray(schema.items)) report.addError("KEYWORD_UNDEFINED_STRICT", ["additionalItems"], void 0, schema, "additionalItems");
|
|
5065
5136
|
if (this.options.assumeAdditional && schema.additionalItems === void 0 && Array.isArray(schema.items)) schema.additionalItems = false;
|
|
5066
5137
|
},
|
|
5067
|
-
maxItems
|
|
5138
|
+
maxItems(report, schema) {
|
|
5068
5139
|
if (typeof schema.maxItems !== "number") report.addError("KEYWORD_TYPE_EXPECTED", ["maxItems", "integer"], void 0, schema, "maxItems");
|
|
5069
5140
|
else if (schema.maxItems < 0) report.addError("KEYWORD_MUST_BE", ["maxItems", "greater than, or equal to 0"], void 0, schema, "maxItems");
|
|
5070
5141
|
},
|
|
5071
|
-
minItems
|
|
5142
|
+
minItems(report, schema) {
|
|
5072
5143
|
if (!isInteger(schema.minItems)) report.addError("KEYWORD_TYPE_EXPECTED", ["minItems", "integer"], void 0, schema, "minItems");
|
|
5073
5144
|
else if (schema.minItems < 0) report.addError("KEYWORD_MUST_BE", ["minItems", "greater than, or equal to 0"], void 0, schema, "minItems");
|
|
5074
5145
|
},
|
|
5075
|
-
uniqueItems
|
|
5146
|
+
uniqueItems(report, schema) {
|
|
5076
5147
|
if (typeof schema.uniqueItems !== "boolean") report.addError("KEYWORD_TYPE_EXPECTED", ["uniqueItems", "boolean"], void 0, schema, "uniqueItems");
|
|
5077
5148
|
},
|
|
5078
|
-
maxProperties
|
|
5149
|
+
maxProperties(report, schema) {
|
|
5079
5150
|
if (!isInteger(schema.maxProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["maxProperties", "integer"], void 0, schema, "maxProperties");
|
|
5080
5151
|
else if (schema.maxProperties < 0) report.addError("KEYWORD_MUST_BE", ["maxProperties", "greater than, or equal to 0"], void 0, schema, "maxProperties");
|
|
5081
5152
|
},
|
|
5082
|
-
minProperties
|
|
5153
|
+
minProperties(report, schema) {
|
|
5083
5154
|
if (!isInteger(schema.minProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["minProperties", "integer"], void 0, schema, "minProperties");
|
|
5084
5155
|
else if (schema.minProperties < 0) report.addError("KEYWORD_MUST_BE", ["minProperties", "greater than, or equal to 0"], void 0, schema, "minProperties");
|
|
5085
5156
|
},
|
|
5086
|
-
required
|
|
5157
|
+
required(report, schema) {
|
|
5087
5158
|
if (!Array.isArray(schema.required)) report.addError("KEYWORD_TYPE_EXPECTED", ["required", "array"], void 0, schema, "required");
|
|
5088
5159
|
else if (report.options.version === "draft-04" && schema.required.length === 0) report.addError("KEYWORD_MUST_BE", ["required", "an array with at least one element"], void 0, schema, "required");
|
|
5089
5160
|
else {
|
|
5090
5161
|
for (const item of schema.required) if (typeof item !== "string") report.addError("KEYWORD_VALUE_TYPE", ["required", "string"], void 0, schema, "required");
|
|
5091
|
-
if (isUniqueArray(schema.required)
|
|
5162
|
+
if (!isUniqueArray(schema.required)) report.addError("KEYWORD_MUST_BE", ["required", "an array with unique items"], void 0, schema, "required");
|
|
5092
5163
|
}
|
|
5093
5164
|
},
|
|
5094
|
-
additionalProperties
|
|
5165
|
+
additionalProperties(report, schema) {
|
|
5095
5166
|
if (typeof schema.additionalProperties !== "boolean" && !isObject(schema.additionalProperties)) report.addError("KEYWORD_TYPE_EXPECTED", ["additionalProperties", ["boolean", "object"]], void 0, schema, "additionalProperties");
|
|
5096
5167
|
else if (isObject(schema.additionalProperties)) {
|
|
5097
5168
|
report.path.push("additionalProperties");
|
|
@@ -5099,7 +5170,7 @@
|
|
|
5099
5170
|
report.path.pop();
|
|
5100
5171
|
}
|
|
5101
5172
|
},
|
|
5102
|
-
properties
|
|
5173
|
+
properties(report, schema) {
|
|
5103
5174
|
if (!isObject(schema.properties)) {
|
|
5104
5175
|
report.addError("KEYWORD_TYPE_EXPECTED", ["properties", "object"], void 0, schema, "properties");
|
|
5105
5176
|
return;
|
|
@@ -5117,7 +5188,7 @@
|
|
|
5117
5188
|
if (this.options.assumeAdditional && schema.additionalProperties === void 0) schema.additionalProperties = false;
|
|
5118
5189
|
if (this.options.forceProperties === true && keys.length === 0) report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["properties"], void 0, schema, "properties");
|
|
5119
5190
|
},
|
|
5120
|
-
patternProperties
|
|
5191
|
+
patternProperties(report, schema) {
|
|
5121
5192
|
if (!isObject(schema.patternProperties)) {
|
|
5122
5193
|
report.addError("KEYWORD_TYPE_EXPECTED", ["patternProperties", "object"], void 0, schema, "patternProperties");
|
|
5123
5194
|
return;
|
|
@@ -5139,93 +5210,52 @@
|
|
|
5139
5210
|
}
|
|
5140
5211
|
if (this.options.forceProperties === true && keys.length === 0) report.addError("CUSTOM_MODE_FORCE_PROPERTIES", ["patternProperties"], void 0, schema, "patternProperties");
|
|
5141
5212
|
},
|
|
5142
|
-
dependencies
|
|
5143
|
-
if (!isObject(schema.dependencies))
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5213
|
+
dependencies(report, schema) {
|
|
5214
|
+
if (!isObject(schema.dependencies)) {
|
|
5215
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["dependencies", "object"], void 0, schema, "dependencies");
|
|
5216
|
+
return;
|
|
5217
|
+
}
|
|
5218
|
+
const keys = Object.keys(schema.dependencies);
|
|
5219
|
+
for (const schemaKey of keys) {
|
|
5220
|
+
const schemaDependency = schema.dependencies[schemaKey];
|
|
5221
|
+
if (isObject(schemaDependency) || report.options.version !== "draft-04" && typeof schemaDependency === "boolean") {
|
|
5222
|
+
report.path.push("dependencies");
|
|
5223
|
+
report.path.push(schemaKey);
|
|
5224
|
+
this.validateSchema(report, schemaDependency);
|
|
5225
|
+
report.path.pop();
|
|
5226
|
+
report.path.pop();
|
|
5227
|
+
} else if (Array.isArray(schemaDependency)) {
|
|
5228
|
+
const depArray = schemaDependency;
|
|
5229
|
+
if (report.options.version === "draft-04" && depArray.length === 0) report.addError("KEYWORD_MUST_BE", ["dependencies", "not empty array"], void 0, schema, "dependencies");
|
|
5230
|
+
for (const dep of depArray) if (typeof dep !== "string") report.addError("KEYWORD_VALUE_TYPE", ["dependencies", "string"], void 0, schema, "dependencies");
|
|
5231
|
+
if (!isUniqueArray(depArray)) report.addError("KEYWORD_MUST_BE", ["dependencies", "an array with unique items"], void 0, schema, "dependencies");
|
|
5232
|
+
} else report.addError("KEYWORD_VALUE_TYPE", ["dependencies", report.options.version === "draft-04" ? "object or array" : "boolean, object or array"], void 0, schema, "dependencies");
|
|
5161
5233
|
}
|
|
5162
5234
|
},
|
|
5163
|
-
enum
|
|
5164
|
-
if (Array.isArray(schema.enum)
|
|
5235
|
+
enum(report, schema) {
|
|
5236
|
+
if (!Array.isArray(schema.enum)) report.addError("KEYWORD_TYPE_EXPECTED", ["enum", "array"], void 0, schema, "enum");
|
|
5165
5237
|
else if (schema.enum.length === 0) report.addError("KEYWORD_MUST_BE", ["enum", "an array with at least one element"], void 0, schema, "enum");
|
|
5166
|
-
else if (isUniqueArray(schema.enum)
|
|
5238
|
+
else if (!isUniqueArray(schema.enum)) report.addError("KEYWORD_MUST_BE", ["enum", "an array with unique elements"], void 0, schema, "enum");
|
|
5167
5239
|
},
|
|
5168
|
-
type
|
|
5169
|
-
const primitiveTypes = [
|
|
5170
|
-
"array",
|
|
5171
|
-
"boolean",
|
|
5172
|
-
"integer",
|
|
5173
|
-
"number",
|
|
5174
|
-
"null",
|
|
5175
|
-
"object",
|
|
5176
|
-
"string"
|
|
5177
|
-
];
|
|
5178
|
-
const primitiveTypeStr = primitiveTypes.join(",");
|
|
5240
|
+
type(report, schema) {
|
|
5179
5241
|
const isArray = Array.isArray(schema.type);
|
|
5180
5242
|
if (Array.isArray(schema.type)) {
|
|
5181
|
-
for (const typeItem of schema.type) if (!
|
|
5182
|
-
if (isUniqueArray(schema.type)
|
|
5243
|
+
for (const typeItem of schema.type) if (!PRIMITIVE_TYPES_SET.has(typeItem)) report.addError("KEYWORD_TYPE_EXPECTED", ["type", PRIMITIVE_TYPE_STR], void 0, schema, "type");
|
|
5244
|
+
if (!isUniqueArray(schema.type)) report.addError("KEYWORD_MUST_BE", ["type", "an object with unique properties"], void 0, schema, "type");
|
|
5183
5245
|
} else if (typeof schema.type === "string") {
|
|
5184
|
-
if (!
|
|
5246
|
+
if (!PRIMITIVE_TYPES_SET.has(schema.type)) report.addError("KEYWORD_TYPE_EXPECTED", ["type", PRIMITIVE_TYPE_STR], void 0, schema, "type");
|
|
5185
5247
|
} else report.addError("KEYWORD_TYPE_EXPECTED", ["type", ["string", "array"]], void 0, schema, "type");
|
|
5186
|
-
if (this.options.noEmptyStrings === true)
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
if (this.options.
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
}
|
|
5195
|
-
}
|
|
5196
|
-
if (this.options.forceProperties === true) {
|
|
5197
|
-
if (schema.type === "object" || isArray && schema.type.includes("object")) {
|
|
5198
|
-
if (schema.properties === void 0 && schema.patternProperties === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["properties"], void 0, schema, "properties");
|
|
5199
|
-
}
|
|
5200
|
-
}
|
|
5201
|
-
if (this.options.forceItems === true) {
|
|
5202
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5203
|
-
if (schema.items === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["items"], void 0, schema, "items");
|
|
5204
|
-
}
|
|
5205
|
-
}
|
|
5206
|
-
if (this.options.forceMinItems === true) {
|
|
5207
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5208
|
-
if (schema.minItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minItems"], void 0, schema, "minItems");
|
|
5209
|
-
}
|
|
5210
|
-
}
|
|
5211
|
-
if (this.options.forceMaxItems === true) {
|
|
5212
|
-
if (schema.type === "array" || isArray && schema.type.includes("array")) {
|
|
5213
|
-
if (schema.maxItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxItems"], void 0, schema, "maxItems");
|
|
5214
|
-
}
|
|
5215
|
-
}
|
|
5216
|
-
if (this.options.forceMinLength === true) {
|
|
5217
|
-
if (schema.type === "string" || isArray && schema.type.includes("string")) {
|
|
5218
|
-
if (schema.minLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minLength"], void 0, schema, "minLength");
|
|
5219
|
-
}
|
|
5220
|
-
}
|
|
5221
|
-
if (this.options.forceMaxLength === true) {
|
|
5222
|
-
if (schema.type === "string" || isArray && schema.type.includes("string")) {
|
|
5223
|
-
if (schema.maxLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxLength"], void 0, schema, "maxLength");
|
|
5224
|
-
}
|
|
5225
|
-
}
|
|
5248
|
+
if (this.options.noEmptyStrings === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.minLength === void 0 && schema.enum === void 0 && schema.format === void 0) schema.minLength = 1;
|
|
5249
|
+
if (this.options.noEmptyArrays === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.minItems === void 0) schema.minItems = 1;
|
|
5250
|
+
if (this.options.forceProperties === true && (schema.type === "object" || isArray && schema.type.includes("object")) && schema.properties === void 0 && schema.patternProperties === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["properties"], void 0, schema, "properties");
|
|
5251
|
+
if (this.options.forceItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.items === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["items"], void 0, schema, "items");
|
|
5252
|
+
if (this.options.forceMinItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.minItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minItems"], void 0, schema, "minItems");
|
|
5253
|
+
if (this.options.forceMaxItems === true && (schema.type === "array" || isArray && schema.type.includes("array")) && schema.maxItems === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxItems"], void 0, schema, "maxItems");
|
|
5254
|
+
if (this.options.forceMinLength === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.minLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["minLength"], void 0, schema, "minLength");
|
|
5255
|
+
if (this.options.forceMaxLength === true && (schema.type === "string" || isArray && schema.type.includes("string")) && schema.maxLength === void 0 && schema.format === void 0 && schema.enum === void 0 && schema.pattern === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["maxLength"], void 0, schema, "maxLength");
|
|
5226
5256
|
},
|
|
5227
|
-
allOf
|
|
5228
|
-
if (Array.isArray(schema.allOf)
|
|
5257
|
+
allOf(report, schema) {
|
|
5258
|
+
if (!Array.isArray(schema.allOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["allOf", "array"], void 0, schema, "allOf");
|
|
5229
5259
|
else if (schema.allOf.length === 0) report.addError("KEYWORD_MUST_BE", ["allOf", "an array with at least one element"], void 0, schema, "allOf");
|
|
5230
5260
|
else for (let idx = 0; idx < schema.allOf.length; idx++) {
|
|
5231
5261
|
report.path.push("allOf");
|
|
@@ -5235,8 +5265,8 @@
|
|
|
5235
5265
|
report.path.pop();
|
|
5236
5266
|
}
|
|
5237
5267
|
},
|
|
5238
|
-
anyOf
|
|
5239
|
-
if (Array.isArray(schema.anyOf)
|
|
5268
|
+
anyOf(report, schema) {
|
|
5269
|
+
if (!Array.isArray(schema.anyOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["anyOf", "array"], void 0, schema, "anyOf");
|
|
5240
5270
|
else if (schema.anyOf.length === 0) report.addError("KEYWORD_MUST_BE", ["anyOf", "an array with at least one element"], void 0, schema, "anyOf");
|
|
5241
5271
|
else for (let idx = 0; idx < schema.anyOf.length; idx++) {
|
|
5242
5272
|
report.path.push("anyOf");
|
|
@@ -5246,8 +5276,8 @@
|
|
|
5246
5276
|
report.path.pop();
|
|
5247
5277
|
}
|
|
5248
5278
|
},
|
|
5249
|
-
oneOf
|
|
5250
|
-
if (Array.isArray(schema.oneOf)
|
|
5279
|
+
oneOf(report, schema) {
|
|
5280
|
+
if (!Array.isArray(schema.oneOf)) report.addError("KEYWORD_TYPE_EXPECTED", ["oneOf", "array"], void 0, schema, "oneOf");
|
|
5251
5281
|
else if (schema.oneOf.length === 0) report.addError("KEYWORD_MUST_BE", ["oneOf", "an array with at least one element"], void 0, schema, "oneOf");
|
|
5252
5282
|
else for (let idx = 0; idx < schema.oneOf.length; idx++) {
|
|
5253
5283
|
report.path.push("oneOf");
|
|
@@ -5257,16 +5287,17 @@
|
|
|
5257
5287
|
report.path.pop();
|
|
5258
5288
|
}
|
|
5259
5289
|
},
|
|
5260
|
-
not
|
|
5290
|
+
not(report, schema) {
|
|
5261
5291
|
const notSchema = schema.not;
|
|
5262
|
-
if (!(report.options.version === "draft-04" ? isObject(notSchema) : typeof notSchema === "boolean" || isObject(notSchema)))
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
this.validateSchema(report, notSchema);
|
|
5266
|
-
report.path.pop();
|
|
5292
|
+
if (!(report.options.version === "draft-04" ? isObject(notSchema) : typeof notSchema === "boolean" || isObject(notSchema))) {
|
|
5293
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["not", report.options.version === "draft-04" ? "object" : ["boolean", "object"]], void 0, schema, "not");
|
|
5294
|
+
return;
|
|
5267
5295
|
}
|
|
5296
|
+
report.path.push("not");
|
|
5297
|
+
this.validateSchema(report, notSchema);
|
|
5298
|
+
report.path.pop();
|
|
5268
5299
|
},
|
|
5269
|
-
if
|
|
5300
|
+
if(report, schema) {
|
|
5270
5301
|
if (report.options.version !== "draft-07") return;
|
|
5271
5302
|
const ifSchema = schema.if;
|
|
5272
5303
|
if (!(typeof ifSchema === "boolean" || isObject(ifSchema))) {
|
|
@@ -5277,7 +5308,7 @@
|
|
|
5277
5308
|
this.validateSchema(report, ifSchema);
|
|
5278
5309
|
report.path.pop();
|
|
5279
5310
|
},
|
|
5280
|
-
then
|
|
5311
|
+
then(report, schema) {
|
|
5281
5312
|
if (report.options.version !== "draft-07") return;
|
|
5282
5313
|
const thenSchema = schema.then;
|
|
5283
5314
|
if (!(typeof thenSchema === "boolean" || isObject(thenSchema))) {
|
|
@@ -5288,7 +5319,7 @@
|
|
|
5288
5319
|
this.validateSchema(report, thenSchema);
|
|
5289
5320
|
report.path.pop();
|
|
5290
5321
|
},
|
|
5291
|
-
else
|
|
5322
|
+
else(report, schema) {
|
|
5292
5323
|
if (report.options.version !== "draft-07") return;
|
|
5293
5324
|
const elseSchema = schema.else;
|
|
5294
5325
|
if (!(typeof elseSchema === "boolean" || isObject(elseSchema))) {
|
|
@@ -5299,21 +5330,22 @@
|
|
|
5299
5330
|
this.validateSchema(report, elseSchema);
|
|
5300
5331
|
report.path.pop();
|
|
5301
5332
|
},
|
|
5302
|
-
definitions
|
|
5303
|
-
if (!isObject(schema.definitions))
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5333
|
+
definitions(report, schema) {
|
|
5334
|
+
if (!isObject(schema.definitions)) {
|
|
5335
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["definitions", "object"], void 0, schema, "definitions");
|
|
5336
|
+
return;
|
|
5337
|
+
}
|
|
5338
|
+
const keys = Object.keys(schema.definitions);
|
|
5339
|
+
for (const key of keys) {
|
|
5340
|
+
const val = schema.definitions[key];
|
|
5341
|
+
report.path.push("definitions");
|
|
5342
|
+
report.path.push(key);
|
|
5343
|
+
this.validateSchema(report, val);
|
|
5344
|
+
report.path.pop();
|
|
5345
|
+
report.path.pop();
|
|
5314
5346
|
}
|
|
5315
5347
|
},
|
|
5316
|
-
$defs
|
|
5348
|
+
$defs(report, schema) {
|
|
5317
5349
|
if (report.options.version !== "draft2019-09" && report.options.version !== "draft2020-12") return;
|
|
5318
5350
|
if (!isObject(schema.$defs)) {
|
|
5319
5351
|
report.addError("KEYWORD_TYPE_EXPECTED", ["$defs", "object"], void 0, schema, "$defs");
|
|
@@ -5329,34 +5361,36 @@
|
|
|
5329
5361
|
report.path.pop();
|
|
5330
5362
|
}
|
|
5331
5363
|
},
|
|
5332
|
-
format
|
|
5364
|
+
format(report, schema) {
|
|
5333
5365
|
if (this.options.formatAssertions === false) return;
|
|
5334
|
-
if (typeof schema.format !== "string")
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
if (!isFormatSupported(schema.format, this.options.customFormats) && this.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
5366
|
+
if (typeof schema.format !== "string") {
|
|
5367
|
+
report.addError("KEYWORD_TYPE_EXPECTED", ["format", "string"], void 0, schema, "format");
|
|
5368
|
+
return;
|
|
5338
5369
|
}
|
|
5370
|
+
const isModernDraft = this.options.version === "draft2019-09" || this.options.version === "draft2020-12";
|
|
5371
|
+
if (!isFormatSupported(schema.format, this.options.customFormats) && this.options.ignoreUnknownFormats !== true && !isModernDraft) report.addError("UNKNOWN_FORMAT", [schema.format], void 0, schema, "format");
|
|
5339
5372
|
},
|
|
5340
|
-
contentEncoding
|
|
5373
|
+
contentEncoding(report, schema) {
|
|
5341
5374
|
if (report.options.version !== "draft-07") return;
|
|
5342
5375
|
if (typeof schema.contentEncoding !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["contentEncoding", "string"], void 0, schema, "contentEncoding");
|
|
5343
5376
|
},
|
|
5344
|
-
contentMediaType
|
|
5377
|
+
contentMediaType(report, schema) {
|
|
5345
5378
|
if (report.options.version !== "draft-07") return;
|
|
5346
5379
|
if (typeof schema.contentMediaType !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["contentMediaType", "string"], void 0, schema, "contentMediaType");
|
|
5347
5380
|
},
|
|
5348
|
-
id
|
|
5381
|
+
id(report, schema) {
|
|
5349
5382
|
if (typeof schema.id !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["id", "string"], void 0, schema, "id");
|
|
5350
5383
|
},
|
|
5351
|
-
title
|
|
5384
|
+
title(report, schema) {
|
|
5352
5385
|
if (typeof schema.title !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["title", "string"], void 0, schema, "title");
|
|
5353
5386
|
},
|
|
5354
|
-
description
|
|
5387
|
+
description(report, schema) {
|
|
5355
5388
|
if (typeof schema.description !== "string") report.addError("KEYWORD_TYPE_EXPECTED", ["description", "string"], void 0, schema, "description");
|
|
5356
5389
|
},
|
|
5357
|
-
default
|
|
5390
|
+
default() {}
|
|
5358
5391
|
};
|
|
5359
5392
|
var SchemaValidator = class {
|
|
5393
|
+
validator;
|
|
5360
5394
|
constructor(validator) {
|
|
5361
5395
|
this.validator = validator;
|
|
5362
5396
|
}
|
|
@@ -5376,18 +5410,17 @@
|
|
|
5376
5410
|
if (hasParentSchema) {
|
|
5377
5411
|
if (schema.__$schemaResolved && schema.__$schemaResolved !== schema) {
|
|
5378
5412
|
const subReport = new Report(report);
|
|
5379
|
-
if (validate
|
|
5413
|
+
if (!validate(this.validator, subReport, schema.__$schemaResolved, schema)) report.addError("PARENT_SCHEMA_VALIDATION_FAILED", void 0, subReport, schema, "$schema");
|
|
5380
5414
|
} else if (this.validator.options.ignoreUnresolvableReferences !== true) report.addError("REF_UNRESOLVED", [schema.$schema], void 0, schema, "$schema");
|
|
5381
5415
|
}
|
|
5382
5416
|
if (this.validator.options.noTypeless === true) {
|
|
5383
5417
|
if (schema.type !== void 0) {
|
|
5384
|
-
|
|
5385
|
-
if (Array.isArray(schema.anyOf)) schemas = schemas.concat(schema.anyOf);
|
|
5386
|
-
if (Array.isArray(schema.oneOf)) schemas = schemas.concat(schema.oneOf);
|
|
5387
|
-
if (Array.isArray(schema.allOf)) schemas = schemas.concat(schema.allOf);
|
|
5388
|
-
schemas.forEach(function(sch) {
|
|
5418
|
+
const inheritType = (sch) => {
|
|
5389
5419
|
if (!sch.type) sch.type = schema.type;
|
|
5390
|
-
}
|
|
5420
|
+
};
|
|
5421
|
+
if (Array.isArray(schema.anyOf)) for (let i = 0; i < schema.anyOf.length; i++) inheritType(schema.anyOf[i]);
|
|
5422
|
+
if (Array.isArray(schema.oneOf)) for (let i = 0; i < schema.oneOf.length; i++) inheritType(schema.oneOf[i]);
|
|
5423
|
+
if (Array.isArray(schema.allOf)) for (let i = 0; i < schema.allOf.length; i++) inheritType(schema.allOf[i]);
|
|
5391
5424
|
}
|
|
5392
5425
|
if (schema.enum === void 0 && schema.type === void 0 && schema.anyOf === void 0 && schema.oneOf === void 0 && schema.not === void 0 && schema.$ref === void 0) report.addError("KEYWORD_UNDEFINED_STRICT", ["type"], void 0, schema, "type");
|
|
5393
5426
|
}
|
|
@@ -5395,9 +5428,7 @@
|
|
|
5395
5428
|
for (const key of keys) {
|
|
5396
5429
|
if (key.startsWith("__")) continue;
|
|
5397
5430
|
if (Object.hasOwn(SchemaValidators, key)) SchemaValidators[key].call(this, report, schema);
|
|
5398
|
-
else if (!hasParentSchema)
|
|
5399
|
-
if (this.validator.options.noExtraKeywords === true) report.addError("KEYWORD_UNEXPECTED", [key], void 0, schema, void 0);
|
|
5400
|
-
}
|
|
5431
|
+
else if (!hasParentSchema && this.validator.options.noExtraKeywords === true) report.addError("KEYWORD_UNEXPECTED", [key], void 0, schema);
|
|
5401
5432
|
}
|
|
5402
5433
|
if (this.validator.options.pedanticCheck === true) {
|
|
5403
5434
|
if (schema.enum) {
|
|
@@ -5407,14 +5438,14 @@
|
|
|
5407
5438
|
report.path.push("enum");
|
|
5408
5439
|
for (let idx = 0; idx < schema.enum.length; idx++) {
|
|
5409
5440
|
report.path.push(idx);
|
|
5410
|
-
validate
|
|
5441
|
+
validate(this.validator, report, tmpSchema, schema.enum[idx]);
|
|
5411
5442
|
report.path.pop();
|
|
5412
5443
|
}
|
|
5413
5444
|
report.path.pop();
|
|
5414
5445
|
}
|
|
5415
5446
|
if (schema.default) {
|
|
5416
5447
|
report.path.push("default");
|
|
5417
|
-
validate
|
|
5448
|
+
validate(this.validator, report, schema, schema.default);
|
|
5418
5449
|
report.path.pop();
|
|
5419
5450
|
}
|
|
5420
5451
|
}
|
|
@@ -5451,7 +5482,7 @@
|
|
|
5451
5482
|
* create a circular dependency).
|
|
5452
5483
|
*/
|
|
5453
5484
|
_jsonValidate(report, schema, json) {
|
|
5454
|
-
return validate
|
|
5485
|
+
return validate(this, report, schema, json);
|
|
5455
5486
|
}
|
|
5456
5487
|
getDefaultSchemaId() {
|
|
5457
5488
|
return this.options.version && this.options.version !== "none" ? VERSION_SCHEMA_URL_MAPPING[this.options.version] : VERSION_SCHEMA_URL_MAPPING[defaultOptions.version];
|
|
@@ -5464,9 +5495,9 @@
|
|
|
5464
5495
|
if (!options) options = {};
|
|
5465
5496
|
this.validateOptions = options;
|
|
5466
5497
|
if (typeof schema !== "string" && typeof schema !== "boolean" && !isObject(schema)) {
|
|
5467
|
-
const e = /* @__PURE__ */ new Error(
|
|
5498
|
+
const e = /* @__PURE__ */ new Error(`Invalid .validate call - schema must be a string or object but ${whatIs(schema)} was passed!`);
|
|
5468
5499
|
if (callback) {
|
|
5469
|
-
setTimeout(
|
|
5500
|
+
setTimeout(() => {
|
|
5470
5501
|
callback(e, false);
|
|
5471
5502
|
}, 0);
|
|
5472
5503
|
return;
|
|
@@ -5481,9 +5512,9 @@
|
|
|
5481
5512
|
const schemaName = schema;
|
|
5482
5513
|
_schema = this.scache.getSchema(report, schemaName);
|
|
5483
5514
|
if (!_schema) {
|
|
5484
|
-
const e = /* @__PURE__ */ new Error(
|
|
5515
|
+
const e = /* @__PURE__ */ new Error(`Schema with id '${schemaName}' wasn't found in the validator cache!`);
|
|
5485
5516
|
if (callback) {
|
|
5486
|
-
setTimeout(
|
|
5517
|
+
setTimeout(() => {
|
|
5487
5518
|
callback(e, false);
|
|
5488
5519
|
}, 0);
|
|
5489
5520
|
return;
|
|
@@ -5501,9 +5532,9 @@
|
|
|
5501
5532
|
report.rootSchema = _schema;
|
|
5502
5533
|
_schema = get(_schema, options.schemaPath);
|
|
5503
5534
|
if (!_schema) {
|
|
5504
|
-
const e = /* @__PURE__ */ new Error(
|
|
5535
|
+
const e = /* @__PURE__ */ new Error(`Schema path '${options.schemaPath}' wasn't found in the schema!`);
|
|
5505
5536
|
if (callback) {
|
|
5506
|
-
setTimeout(
|
|
5537
|
+
setTimeout(() => {
|
|
5507
5538
|
callback(e, false);
|
|
5508
5539
|
}, 0);
|
|
5509
5540
|
return;
|
|
@@ -5511,7 +5542,7 @@
|
|
|
5511
5542
|
throw e;
|
|
5512
5543
|
}
|
|
5513
5544
|
}
|
|
5514
|
-
if (!foundError) validate
|
|
5545
|
+
if (!foundError) validate(this, report, _schema, json);
|
|
5515
5546
|
if (callback) {
|
|
5516
5547
|
report.processAsyncTasks(this.options.asyncTimeout, callback);
|
|
5517
5548
|
return;
|
|
@@ -5582,8 +5613,8 @@
|
|
|
5582
5613
|
if (!err) return [];
|
|
5583
5614
|
const details = err.details || [];
|
|
5584
5615
|
const missingRefs = [];
|
|
5585
|
-
function collect(
|
|
5586
|
-
for (const detail of
|
|
5616
|
+
function collect(items) {
|
|
5617
|
+
for (const detail of items) {
|
|
5587
5618
|
if (detail.code === "UNRESOLVABLE_REFERENCE" || detail.code === "SCHEMA_NOT_REACHABLE") missingRefs.push(detail.params[0]);
|
|
5588
5619
|
if (detail.inner) collect(detail.inner);
|
|
5589
5620
|
}
|
|
@@ -5599,9 +5630,13 @@
|
|
|
5599
5630
|
getMissingRemoteReferences(err) {
|
|
5600
5631
|
const missingReferences = this.getMissingReferences(err);
|
|
5601
5632
|
const missingRemoteReferences = [];
|
|
5633
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5602
5634
|
for (const ref of missingReferences) {
|
|
5603
5635
|
const remoteReference = getRemotePath(ref);
|
|
5604
|
-
if (remoteReference && !
|
|
5636
|
+
if (remoteReference && !seen.has(remoteReference)) {
|
|
5637
|
+
seen.add(remoteReference);
|
|
5638
|
+
missingRemoteReferences.push(remoteReference);
|
|
5639
|
+
}
|
|
5605
5640
|
}
|
|
5606
5641
|
return missingRemoteReferences;
|
|
5607
5642
|
}
|
|
@@ -5614,24 +5649,25 @@
|
|
|
5614
5649
|
getResolvedSchema(schemaId) {
|
|
5615
5650
|
const report = new Report(this.options);
|
|
5616
5651
|
const schema = this.scache.getSchemaByUri(report, schemaId);
|
|
5617
|
-
if (!schema) return
|
|
5652
|
+
if (!schema) return;
|
|
5618
5653
|
const clonedSchema = deepClone(schema, this.options.maxRecursionDepth);
|
|
5619
5654
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
5620
|
-
const cleanup =
|
|
5621
|
-
|
|
5622
|
-
const typeOf = whatIs(schema);
|
|
5655
|
+
const cleanup = (node) => {
|
|
5656
|
+
const typeOf = whatIs(node);
|
|
5623
5657
|
if (typeOf !== "object" && typeOf !== "array") return;
|
|
5624
|
-
if (visited.has(
|
|
5625
|
-
visited.add(
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
const
|
|
5629
|
-
|
|
5630
|
-
delete
|
|
5631
|
-
|
|
5658
|
+
if (visited.has(node)) return;
|
|
5659
|
+
visited.add(node);
|
|
5660
|
+
const schemaNode = node;
|
|
5661
|
+
if (schemaNode.$ref && schemaNode.__$refResolved) {
|
|
5662
|
+
const from = schemaNode.__$refResolved;
|
|
5663
|
+
const to = schemaNode;
|
|
5664
|
+
delete schemaNode.$ref;
|
|
5665
|
+
delete schemaNode.__$refResolved;
|
|
5666
|
+
for (const key in from) if (Object.hasOwn(from, key)) copyProp(from, to, key);
|
|
5632
5667
|
}
|
|
5633
|
-
|
|
5634
|
-
|
|
5668
|
+
const record = node;
|
|
5669
|
+
for (const key in record) if (Object.hasOwn(record, key)) if (isInternalKey(key)) delete record[key];
|
|
5670
|
+
else cleanup(record[key]);
|
|
5635
5671
|
};
|
|
5636
5672
|
cleanup(clonedSchema);
|
|
5637
5673
|
return clonedSchema;
|
|
@@ -5640,24 +5676,20 @@
|
|
|
5640
5676
|
//#endregion
|
|
5641
5677
|
//#region src/z-schema.ts
|
|
5642
5678
|
var ZSchema = class ZSchema extends ZSchemaBase {
|
|
5643
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5644
|
-
constructor(options, token) {
|
|
5645
|
-
super(options, token);
|
|
5646
|
-
}
|
|
5647
5679
|
/**
|
|
5648
5680
|
* Register a global format validator available to all instances.
|
|
5649
5681
|
* @param name - The format name (e.g. `'email'`, `'date'`).
|
|
5650
5682
|
* @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
|
|
5651
5683
|
*/
|
|
5652
5684
|
static registerFormat(name, validatorFunction) {
|
|
5653
|
-
|
|
5685
|
+
registerFormat(name, validatorFunction);
|
|
5654
5686
|
}
|
|
5655
5687
|
/**
|
|
5656
5688
|
* Remove a globally registered format validator.
|
|
5657
5689
|
* @param name - The format name to unregister.
|
|
5658
5690
|
*/
|
|
5659
5691
|
static unregisterFormat(name) {
|
|
5660
|
-
|
|
5692
|
+
unregisterFormat(name);
|
|
5661
5693
|
}
|
|
5662
5694
|
/** Returns the names of all globally registered format validators. */
|
|
5663
5695
|
static getRegisteredFormats() {
|
|
@@ -5686,7 +5718,7 @@
|
|
|
5686
5718
|
* @param schemaReader - A function `(uri: string) => JsonSchema | undefined`, or `undefined` to clear.
|
|
5687
5719
|
*/
|
|
5688
5720
|
static setSchemaReader(schemaReader) {
|
|
5689
|
-
|
|
5721
|
+
setSchemaReader(schemaReader);
|
|
5690
5722
|
}
|
|
5691
5723
|
static schemaSymbol = schemaSymbol;
|
|
5692
5724
|
static jsonSymbol = jsonSymbol;
|
|
@@ -5722,10 +5754,10 @@
|
|
|
5722
5754
|
try {
|
|
5723
5755
|
this._validate(json, schema, options ?? {});
|
|
5724
5756
|
return { valid: true };
|
|
5725
|
-
} catch (
|
|
5757
|
+
} catch (error) {
|
|
5726
5758
|
return {
|
|
5727
5759
|
valid: false,
|
|
5728
|
-
err
|
|
5760
|
+
err: error
|
|
5729
5761
|
};
|
|
5730
5762
|
}
|
|
5731
5763
|
}
|
|
@@ -5740,9 +5772,12 @@
|
|
|
5740
5772
|
validateAsync(json, schema, options) {
|
|
5741
5773
|
return new Promise((resolve, reject) => {
|
|
5742
5774
|
try {
|
|
5743
|
-
this._validate(json, schema, options || {}, (err, valid) =>
|
|
5744
|
-
|
|
5745
|
-
|
|
5775
|
+
this._validate(json, schema, options || {}, (err, valid) => {
|
|
5776
|
+
if (err || !valid) reject(err ?? /* @__PURE__ */ new Error("Validation failed"));
|
|
5777
|
+
else resolve(valid);
|
|
5778
|
+
});
|
|
5779
|
+
} catch (error) {
|
|
5780
|
+
reject(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
5746
5781
|
}
|
|
5747
5782
|
});
|
|
5748
5783
|
}
|
|
@@ -5763,10 +5798,10 @@
|
|
|
5763
5798
|
err
|
|
5764
5799
|
});
|
|
5765
5800
|
});
|
|
5766
|
-
} catch (
|
|
5801
|
+
} catch (error) {
|
|
5767
5802
|
resolve({
|
|
5768
5803
|
valid: false,
|
|
5769
|
-
err
|
|
5804
|
+
err: error
|
|
5770
5805
|
});
|
|
5771
5806
|
}
|
|
5772
5807
|
});
|
|
@@ -5789,10 +5824,10 @@
|
|
|
5789
5824
|
try {
|
|
5790
5825
|
this._validateSchema(schemaOrArr);
|
|
5791
5826
|
return { valid: true };
|
|
5792
|
-
} catch (
|
|
5827
|
+
} catch (error) {
|
|
5793
5828
|
return {
|
|
5794
5829
|
valid: false,
|
|
5795
|
-
err
|
|
5830
|
+
err: error
|
|
5796
5831
|
};
|
|
5797
5832
|
}
|
|
5798
5833
|
}
|
|
@@ -5802,10 +5837,6 @@
|
|
|
5802
5837
|
* Created via `ZSchema.create({ safe: true })`.
|
|
5803
5838
|
*/
|
|
5804
5839
|
var ZSchemaSafe = class extends ZSchemaBase {
|
|
5805
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5806
|
-
constructor(options, token) {
|
|
5807
|
-
super(options, token);
|
|
5808
|
-
}
|
|
5809
5840
|
/**
|
|
5810
5841
|
* Validate JSON data against a schema.
|
|
5811
5842
|
* @param json - The data to validate.
|
|
@@ -5817,10 +5848,10 @@
|
|
|
5817
5848
|
try {
|
|
5818
5849
|
this._validate(json, schema, options);
|
|
5819
5850
|
return { valid: true };
|
|
5820
|
-
} catch (
|
|
5851
|
+
} catch (error) {
|
|
5821
5852
|
return {
|
|
5822
5853
|
valid: false,
|
|
5823
|
-
err
|
|
5854
|
+
err: error
|
|
5824
5855
|
};
|
|
5825
5856
|
}
|
|
5826
5857
|
}
|
|
@@ -5833,10 +5864,10 @@
|
|
|
5833
5864
|
try {
|
|
5834
5865
|
this._validateSchema(schemaOrArr);
|
|
5835
5866
|
return { valid: true };
|
|
5836
|
-
} catch (
|
|
5867
|
+
} catch (error) {
|
|
5837
5868
|
return {
|
|
5838
5869
|
valid: false,
|
|
5839
|
-
err
|
|
5870
|
+
err: error
|
|
5840
5871
|
};
|
|
5841
5872
|
}
|
|
5842
5873
|
}
|
|
@@ -5846,10 +5877,6 @@
|
|
|
5846
5877
|
* Created via `ZSchema.create({ async: true })`.
|
|
5847
5878
|
*/
|
|
5848
5879
|
var ZSchemaAsync = class extends ZSchemaBase {
|
|
5849
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5850
|
-
constructor(options, token) {
|
|
5851
|
-
super(options, token);
|
|
5852
|
-
}
|
|
5853
5880
|
/**
|
|
5854
5881
|
* Validate JSON data against a schema asynchronously.
|
|
5855
5882
|
* @param json - The data to validate.
|
|
@@ -5861,9 +5888,12 @@
|
|
|
5861
5888
|
validate(json, schema, options = {}) {
|
|
5862
5889
|
return new Promise((resolve, reject) => {
|
|
5863
5890
|
try {
|
|
5864
|
-
this._validate(json, schema, options, (err, valid) =>
|
|
5865
|
-
|
|
5866
|
-
|
|
5891
|
+
this._validate(json, schema, options, (err, valid) => {
|
|
5892
|
+
if (err || !valid) reject(err ?? /* @__PURE__ */ new Error("Validation failed"));
|
|
5893
|
+
else resolve(valid);
|
|
5894
|
+
});
|
|
5895
|
+
} catch (error) {
|
|
5896
|
+
reject(error instanceof Error ? error : new Error(String(error), { cause: error }));
|
|
5867
5897
|
}
|
|
5868
5898
|
});
|
|
5869
5899
|
}
|
|
@@ -5882,10 +5912,6 @@
|
|
|
5882
5912
|
* Created via `ZSchema.create({ async: true, safe: true })`.
|
|
5883
5913
|
*/
|
|
5884
5914
|
var ZSchemaAsyncSafe = class extends ZSchemaBase {
|
|
5885
|
-
/** @internal Use ZSchema.create() instead. */
|
|
5886
|
-
constructor(options, token) {
|
|
5887
|
-
super(options, token);
|
|
5888
|
-
}
|
|
5889
5915
|
/**
|
|
5890
5916
|
* Validate JSON data against a schema asynchronously.
|
|
5891
5917
|
* The promise always resolves (never rejects).
|
|
@@ -5903,10 +5929,10 @@
|
|
|
5903
5929
|
err
|
|
5904
5930
|
});
|
|
5905
5931
|
});
|
|
5906
|
-
} catch (
|
|
5932
|
+
} catch (error) {
|
|
5907
5933
|
resolve({
|
|
5908
5934
|
valid: false,
|
|
5909
|
-
err
|
|
5935
|
+
err: error
|
|
5910
5936
|
});
|
|
5911
5937
|
}
|
|
5912
5938
|
});
|
|
@@ -5920,10 +5946,10 @@
|
|
|
5920
5946
|
try {
|
|
5921
5947
|
this._validateSchema(schemaOrArr);
|
|
5922
5948
|
return { valid: true };
|
|
5923
|
-
} catch (
|
|
5949
|
+
} catch (error) {
|
|
5924
5950
|
return {
|
|
5925
5951
|
valid: false,
|
|
5926
|
-
err
|
|
5952
|
+
err: error
|
|
5927
5953
|
};
|
|
5928
5954
|
}
|
|
5929
5955
|
}
|