@hyperjump/json-schema 1.9.4 → 1.9.6
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 +10 -2
- package/lib/core.js +1 -1
- package/lib/instance.js +0 -4
- package/lib/keywords/if.js +2 -2
- package/lib/keywords/validation.js +1 -3
- package/lib/output.js +1 -3
- package/lib/schema.js +4 -2
- package/package.json +1 -1
|
@@ -16,11 +16,11 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
|
|
|
16
16
|
const keywordUri = getKeywordId(keyword, dialect);
|
|
17
17
|
|
|
18
18
|
let currentNode = node.root;
|
|
19
|
-
const errors =
|
|
19
|
+
const errors = [...invalidSchemas(currentNode)];
|
|
20
20
|
for (let segment of JsonPointer.pointerSegments(node.pointer)) {
|
|
21
21
|
segment = segment === "-" && Instance.typeOf(currentNode) === "array" ? Instance.length(currentNode) : segment;
|
|
22
22
|
currentNode = Instance.step(segment, currentNode);
|
|
23
|
-
errors.push(...
|
|
23
|
+
errors.push(...invalidSchemas(currentNode));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const annotations = [];
|
|
@@ -33,6 +33,14 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
|
|
|
33
33
|
return annotations;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const invalidSchemas = function* (node) {
|
|
37
|
+
for (const error in node.errors) {
|
|
38
|
+
if (node.errors[error] === "https://json-schema.org/evaluation/validate") {
|
|
39
|
+
yield error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
36
44
|
export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) => {
|
|
37
45
|
const nodes = [];
|
|
38
46
|
|
package/lib/core.js
CHANGED
|
@@ -43,7 +43,7 @@ subscribe("validate.metaValidate", async (_message, schema) => {
|
|
|
43
43
|
|
|
44
44
|
// Compile
|
|
45
45
|
if (!(schema.document.dialectId in metaValidators)) {
|
|
46
|
-
const metaSchema = await getSchema(schema.document.dialectId);
|
|
46
|
+
const metaSchema = await getSchema(schema.document.dialectId, schema);
|
|
47
47
|
const compiledSchema = await compile(metaSchema);
|
|
48
48
|
metaValidators[schema.document.dialectId] = interpret(compiledSchema);
|
|
49
49
|
}
|
package/lib/instance.js
CHANGED
|
@@ -76,10 +76,6 @@ export const typeOf = (node) => node.type;
|
|
|
76
76
|
export const has = (key, node) => key in node.value;
|
|
77
77
|
|
|
78
78
|
export const step = (key, node) => {
|
|
79
|
-
if (node.type !== "object" && node.type !== "array") {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
79
|
switch (node.type) {
|
|
84
80
|
case "object":
|
|
85
81
|
const property = node.children.find((propertyNode) => {
|
package/lib/keywords/if.js
CHANGED
|
@@ -5,8 +5,8 @@ const id = "https://json-schema.org/keyword/if";
|
|
|
5
5
|
|
|
6
6
|
const compile = (schema, ast) => Validation.compile(schema, ast);
|
|
7
7
|
|
|
8
|
-
const interpret = (ifSchema, instance, ast, dynamicAnchors
|
|
9
|
-
Validation.interpret(ifSchema, instance, ast, dynamicAnchors,
|
|
8
|
+
const interpret = (ifSchema, instance, ast, dynamicAnchors) => {
|
|
9
|
+
Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true);
|
|
10
10
|
return true;
|
|
11
11
|
};
|
|
12
12
|
|
package/lib/output.js
CHANGED
|
@@ -25,7 +25,7 @@ outputFormats.BASIC = (instance) => {
|
|
|
25
25
|
|
|
26
26
|
for (const child of Instance.allNodes(instance)) {
|
|
27
27
|
for (const [absoluteKeywordLocation, keyword] of Object.entries(child.errors).reverse()) {
|
|
28
|
-
if (!child.valid) {
|
|
28
|
+
if (keyword !== "https://json-schema.org/evaluation/validate" && !child.valid) {
|
|
29
29
|
output.errors.unshift({
|
|
30
30
|
keyword,
|
|
31
31
|
absoluteKeywordLocation,
|
|
@@ -35,8 +35,6 @@ outputFormats.BASIC = (instance) => {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
output.errors.pop();
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
return output;
|
package/lib/schema.js
CHANGED
|
@@ -22,13 +22,15 @@ const schemaRegistry = {};
|
|
|
22
22
|
export const getSchema = async (uri, browser = undefined) => {
|
|
23
23
|
if (!browser) {
|
|
24
24
|
browser = { _cache: {} };
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
for (const uri in schemaRegistry) {
|
|
28
|
+
if (!(uri in browser._cache)) {
|
|
27
29
|
browser._cache[uri] = schemaRegistry[uri];
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
const schema = await browserGet(uri, browser);
|
|
33
|
+
const schema = await browserGet(uri, { ...browser });
|
|
32
34
|
if (typeof schema.document.dialectId !== "string") {
|
|
33
35
|
throw Error(`The document at ${schema.document.baseUri} is not a schema.`);
|
|
34
36
|
}
|