@hyperjump/json-schema 1.4.4 → 1.4.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/README.md +7 -7
- package/bundle/index.js +1 -1
- package/lib/common.js +1 -1
- package/lib/keywords/additionalProperties.js +22 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -409,13 +409,13 @@ addSchema({
|
|
|
409
409
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
410
410
|
|
|
411
411
|
"$vocabulary": {
|
|
412
|
-
"https://json-schema.org/vocab/core": true,
|
|
413
|
-
"https://json-schema.org/vocab/applicator": true,
|
|
414
|
-
"https://json-schema.org/vocab/unevaluated": true,
|
|
415
|
-
"https://json-schema.org/vocab/validation": true,
|
|
416
|
-
"https://json-schema.org/vocab/meta-data": true,
|
|
417
|
-
"https://json-schema.org/vocab/format-annotation": true,
|
|
418
|
-
"https://json-schema.org/vocab/content": true
|
|
412
|
+
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
|
413
|
+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
|
414
|
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
|
415
|
+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
|
416
|
+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
|
417
|
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
|
418
|
+
"https://json-schema.org/draft/2020-12/vocab/content": true
|
|
419
419
|
"https://example.com/vocab/logic": true
|
|
420
420
|
},
|
|
421
421
|
|
package/bundle/index.js
CHANGED
|
@@ -92,7 +92,7 @@ const loadKeywordSupport = () => {
|
|
|
92
92
|
|
|
93
93
|
const additionalProperties = getKeyword("https://json-schema.org/keyword/additionalProperties");
|
|
94
94
|
if (additionalProperties) {
|
|
95
|
-
additionalProperties.collectExternalIds = ([,
|
|
95
|
+
additionalProperties.collectExternalIds = ([, additionalProperties], externalIds, ast, dynamicAnchors) => {
|
|
96
96
|
if (typeof additionalProperties === "string") {
|
|
97
97
|
Validation.collectExternalIds(additionalProperties, externalIds, ast, dynamicAnchors);
|
|
98
98
|
}
|
package/lib/common.js
CHANGED
|
@@ -7,35 +7,50 @@ import Validation from "./validation.js";
|
|
|
7
7
|
const id = "https://json-schema.org/keyword/additionalProperties";
|
|
8
8
|
|
|
9
9
|
const compile = async (schema, ast, parentSchema) => {
|
|
10
|
+
const patterns = [];
|
|
11
|
+
|
|
10
12
|
const propertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/properties");
|
|
11
13
|
const propertiesSchema = await Schema.step(propertiesKeyword, parentSchema);
|
|
12
|
-
|
|
14
|
+
if (Schema.typeOf(propertiesSchema, "object")) {
|
|
15
|
+
for (const name of Schema.keys(propertiesSchema)) {
|
|
16
|
+
patterns.push(regexEscape(name));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
const patternPropertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/patternProperties");
|
|
15
21
|
const patternProperties = await Schema.step(patternPropertiesKeyword, parentSchema);
|
|
16
|
-
|
|
22
|
+
if (Schema.typeOf(patternProperties, "object")) {
|
|
23
|
+
patterns.push(...Schema.keys(patternProperties));
|
|
24
|
+
}
|
|
17
25
|
|
|
18
|
-
return [
|
|
26
|
+
return [
|
|
27
|
+
new RegExp(patterns.length > 0 ? patterns.join("|") : "(?!)", "u"),
|
|
28
|
+
await Validation.compile(schema, ast)
|
|
29
|
+
];
|
|
19
30
|
};
|
|
20
31
|
|
|
21
|
-
const
|
|
32
|
+
const regexEscape = (string) => string
|
|
33
|
+
.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&")
|
|
34
|
+
.replace(/-/g, "\\x2d");
|
|
35
|
+
|
|
36
|
+
const interpret = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors, quiet) => {
|
|
22
37
|
if (!Instance.typeOf(instance, "object")) {
|
|
23
38
|
return true;
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
return Instance.entries(instance)
|
|
27
|
-
.filter(([propertyName]) => !
|
|
42
|
+
.filter(([propertyName]) => !isDefinedProperty.test(propertyName))
|
|
28
43
|
.every(([, property]) => Validation.interpret(additionalProperties, property, ast, dynamicAnchors, quiet));
|
|
29
44
|
};
|
|
30
45
|
|
|
31
|
-
const collectEvaluatedProperties = ([
|
|
46
|
+
const collectEvaluatedProperties = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors) => {
|
|
32
47
|
if (!Instance.typeOf(instance, "object")) {
|
|
33
48
|
return true;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
const evaluatedPropertyNames = new Set();
|
|
37
52
|
for (const [propertyName, property] of Instance.entries(instance)) {
|
|
38
|
-
if (!
|
|
53
|
+
if (!isDefinedProperty.test(propertyName)) {
|
|
39
54
|
if (!Validation.interpret(additionalProperties, property, ast, dynamicAnchors, true)) {
|
|
40
55
|
return false;
|
|
41
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperjump/json-schema",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
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",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@hyperjump/json-pointer": "^1.0.0",
|
|
67
67
|
"@hyperjump/pact": "^0.2.4",
|
|
68
|
-
"@hyperjump/uri": "^1.
|
|
68
|
+
"@hyperjump/uri": "^1.2.0",
|
|
69
69
|
"content-type": "^1.0.4",
|
|
70
70
|
"fastest-stable-stringify": "^2.0.2",
|
|
71
71
|
"just-curry-it": "^5.3.0",
|