@hyperjump/json-schema 1.7.2 → 1.7.3
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/annotations/annotated-instance.js +3 -3
- package/lib/index.js +1 -1
- package/lib/instance.js +2 -2
- package/lib/keywords/allOf.js +22 -8
- package/lib/keywords/anyOf.js +18 -6
- package/lib/keywords/oneOf.js +22 -14
- package/lib/keywords/propertyDependencies.js +15 -10
- package/lib/keywords/validation.js +3 -3
- package/package.json +3 -2
|
@@ -5,8 +5,8 @@ import { getKeywordId } from "../lib/keywords.js";
|
|
|
5
5
|
|
|
6
6
|
const defaultDialectId = "https://json-schema.org/validation";
|
|
7
7
|
|
|
8
|
-
export const nil = { ...nilInstance, annotations: {} };
|
|
9
|
-
export const cons = (instance, id = undefined) => ({
|
|
8
|
+
export const nil = { ...nilInstance, annotations: {} }; // eslint-disable-line import/export
|
|
9
|
+
export const cons = (instance, id = undefined) => ({ // eslint-disable-line import/export
|
|
10
10
|
...nil,
|
|
11
11
|
id: id ? toAbsoluteIri(id) : "",
|
|
12
12
|
instance,
|
|
@@ -47,4 +47,4 @@ export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) =
|
|
|
47
47
|
return instances;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
export * from "../lib/instance.js";
|
|
50
|
+
export * from "../lib/instance.js"; // eslint-disable-line import/export
|
package/lib/index.js
CHANGED
|
@@ -94,6 +94,7 @@ addKeyword(exclusiveMinimum);
|
|
|
94
94
|
addKeyword(format);
|
|
95
95
|
addKeyword(id);
|
|
96
96
|
addKeyword(if_);
|
|
97
|
+
addKeyword(itemPattern);
|
|
97
98
|
addKeyword(items);
|
|
98
99
|
addKeyword(maxContains);
|
|
99
100
|
addKeyword(maxItems);
|
|
@@ -118,7 +119,6 @@ addKeyword(readOnly);
|
|
|
118
119
|
addKeyword(ref);
|
|
119
120
|
addKeyword(requireAllExcept);
|
|
120
121
|
addKeyword(required);
|
|
121
|
-
addKeyword(itemPattern);
|
|
122
122
|
addKeyword(title);
|
|
123
123
|
addKeyword(then);
|
|
124
124
|
addKeyword(type);
|
package/lib/instance.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { append as pointerAppend, get as pointerGet } from "@hyperjump/json-pointer";
|
|
2
2
|
import { toAbsoluteIri } from "@hyperjump/uri";
|
|
3
|
-
import { jsonTypeOf } from "./common.js";
|
|
3
|
+
import { jsonTypeOf, uriFragment } from "./common.js";
|
|
4
4
|
import { Reference } from "@hyperjump/browser/jref";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ export const get = (url, instance = nil) => {
|
|
|
17
17
|
throw Error(`No JSON document found at '${url.split("#")[0]}'`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const pointer = url
|
|
20
|
+
const pointer = uriFragment(url);
|
|
21
21
|
return {
|
|
22
22
|
...instance,
|
|
23
23
|
pointer: pointer,
|
package/lib/keywords/allOf.js
CHANGED
|
@@ -16,17 +16,31 @@ const interpret = (allOf, instance, ast, dynamicAnchors, quiet) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const collectEvaluatedProperties = (allOf, instance, ast, dynamicAnchors) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const evaluatedPropertyNames = new Set();
|
|
20
|
+
for (const schemaUrl of allOf) {
|
|
21
|
+
const propertyNames = Validation.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors);
|
|
22
|
+
if (!propertyNames) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
propertyNames.forEach(evaluatedPropertyNames.add, evaluatedPropertyNames);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return evaluatedPropertyNames;
|
|
23
30
|
};
|
|
24
31
|
|
|
25
32
|
const collectEvaluatedItems = (allOf, instance, ast, dynamicAnchors) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
const evaluatedItemIndexes = new Set();
|
|
34
|
+
for (const schemaUrl of allOf) {
|
|
35
|
+
const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors);
|
|
36
|
+
if (!itemIndexes) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
itemIndexes.forEach(evaluatedItemIndexes.add, evaluatedItemIndexes);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return evaluatedItemIndexes;
|
|
30
44
|
};
|
|
31
45
|
|
|
32
46
|
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords/anyOf.js
CHANGED
|
@@ -17,17 +17,29 @@ const interpret = (anyOf, instance, ast, dynamicAnchors, quiet) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const collectEvaluatedProperties = (anyOf, instance, ast, dynamicAnchors) => {
|
|
20
|
-
|
|
20
|
+
let evaluatedPropertyNames = false;
|
|
21
|
+
for (const schemaUrl of anyOf) {
|
|
21
22
|
const propertyNames = Validation.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors);
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
if (propertyNames) {
|
|
24
|
+
evaluatedPropertyNames ||= new Set();
|
|
25
|
+
propertyNames.forEach(evaluatedPropertyNames.add, evaluatedPropertyNames);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return evaluatedPropertyNames;
|
|
24
30
|
};
|
|
25
31
|
|
|
26
32
|
const collectEvaluatedItems = (anyOf, instance, ast, dynamicAnchors) => {
|
|
27
|
-
|
|
33
|
+
let evaluatedItemIndexes = false;
|
|
34
|
+
for (const schemaUrl of anyOf) {
|
|
28
35
|
const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors);
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
if (itemIndexes) {
|
|
37
|
+
evaluatedItemIndexes ||= new Set();
|
|
38
|
+
itemIndexes.forEach(evaluatedItemIndexes.add, evaluatedItemIndexes);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return evaluatedItemIndexes;
|
|
31
43
|
};
|
|
32
44
|
|
|
33
45
|
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords/oneOf.js
CHANGED
|
@@ -27,27 +27,35 @@ const interpret = (oneOf, instance, ast, dynamicAnchors, quiet) => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const collectEvaluatedProperties = (oneOf, instance, ast, dynamicAnchors) => {
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
let evaluatedProperties = false;
|
|
31
|
+
for (const schemaUrl of oneOf) {
|
|
32
|
+
const propertyNames = Validation.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors);
|
|
33
|
+
if (propertyNames) {
|
|
34
|
+
if (evaluatedProperties) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
evaluatedProperties = propertyNames;
|
|
34
39
|
}
|
|
40
|
+
}
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
return propertyNames ? validCount++ === 0 && propertyNames : acc;
|
|
38
|
-
}, false);
|
|
42
|
+
return evaluatedProperties;
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
const collectEvaluatedItems = (oneOf, instance, ast, dynamicAnchors) => {
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
let evaluatedItemIndexes = false;
|
|
47
|
+
for (const schemaUrl of oneOf) {
|
|
48
|
+
const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors);
|
|
49
|
+
if (itemIndexes) {
|
|
50
|
+
if (evaluatedItemIndexes) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
evaluatedItemIndexes = itemIndexes;
|
|
46
55
|
}
|
|
56
|
+
}
|
|
47
57
|
|
|
48
|
-
|
|
49
|
-
return itemIndexes ? validCount++ === 0 && itemIndexes : acc;
|
|
50
|
-
}, false);
|
|
58
|
+
return evaluatedItemIndexes;
|
|
51
59
|
};
|
|
52
60
|
|
|
53
61
|
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
|
@@ -30,17 +30,22 @@ const interpret = (propertyDependencies, instance, ast, dynamicAnchors, quiet) =
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const collectEvaluatedProperties = (propertyDependencies, instance, ast, dynamicAnchors) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return
|
|
33
|
+
const evaluatedPropertyNames = new Set();
|
|
34
|
+
for (const propertyName in propertyDependencies) {
|
|
35
|
+
const propertyValue = Instance.value(instance)[propertyName];
|
|
36
|
+
|
|
37
|
+
const valueMappings = propertyDependencies[propertyName];
|
|
38
|
+
if (Instance.has(propertyName, instance) && propertyValue in valueMappings) {
|
|
39
|
+
const propertyNames = Validation.collectEvaluatedProperties(valueMappings[propertyValue], instance, ast, dynamicAnchors);
|
|
40
|
+
if (!propertyNames) {
|
|
41
|
+
return false;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
propertyNames.forEach(evaluatedPropertyNames.add, evaluatedPropertyNames);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return evaluatedPropertyNames;
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
export default { id, compile, interpret, collectEvaluatedProperties };
|
|
@@ -77,7 +77,7 @@ const interpret = (url, instance, ast, dynamicAnchors, quiet = false) => {
|
|
|
77
77
|
const emptyPropertyNames = new Set();
|
|
78
78
|
const collectEvaluatedProperties = (url, instance, ast, dynamicAnchors, isTop = false) => {
|
|
79
79
|
if (typeof ast[url] === "boolean") {
|
|
80
|
-
return ast[url] ?
|
|
80
|
+
return ast[url] ? new Set() : false;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const accumulatedPropertyNames = new Set();
|
|
@@ -95,7 +95,7 @@ const collectEvaluatedProperties = (url, instance, ast, dynamicAnchors, isTop =
|
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
propertyNames.forEach(
|
|
98
|
+
propertyNames.forEach(accumulatedPropertyNames.add, accumulatedPropertyNames);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
return accumulatedPropertyNames;
|
|
@@ -122,7 +122,7 @@ const collectEvaluatedItems = (url, instance, ast, dynamicAnchors, isTop = false
|
|
|
122
122
|
return false;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
itemIndexes.forEach(
|
|
125
|
+
itemIndexes.forEach(accumulatedItemIndexes.add, accumulatedItemIndexes);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
return accumulatedItemIndexes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperjump/json-schema",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./stable/index.js",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "xargs -a .gitignore rm -rf",
|
|
24
24
|
"lint": "eslint lib stable draft-* openapi-* bundle annotations",
|
|
25
|
-
"test": "vitest --watch=false"
|
|
25
|
+
"test": "vitest --watch=false",
|
|
26
|
+
"check-types": "tsc --noEmit"
|
|
26
27
|
},
|
|
27
28
|
"repository": {
|
|
28
29
|
"type": "git",
|