@hyperjump/json-schema 1.13.0 → 1.14.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 +14 -20
- package/annotations/index.js +27 -7
- package/annotations/test-utils.d.ts +1 -0
- package/annotations/test-utils.js +38 -0
- package/bundle/index.js +39 -227
- package/draft-04/additionalItems.js +13 -19
- package/draft-04/dependencies.js +7 -7
- package/draft-04/items.js +26 -14
- package/draft-2020-12/dynamicRef.js +20 -8
- package/lib/core.js +19 -4
- package/lib/evaluation-plugins/annotations.js +32 -0
- package/lib/evaluation-plugins/basic-output.js +34 -0
- package/lib/evaluation-plugins/detailed-output.js +36 -0
- package/lib/experimental.d.ts +18 -5
- package/lib/experimental.js +3 -0
- package/lib/instance.js +12 -3
- package/lib/keywords/additionalProperties.js +8 -22
- package/lib/keywords/allOf.js +1 -29
- package/lib/keywords/anyOf.js +1 -27
- package/lib/keywords/conditional.js +1 -27
- package/lib/keywords/contains.js +14 -18
- package/lib/keywords/contentSchema.js +6 -3
- package/lib/keywords/dependentSchemas.js +1 -21
- package/lib/keywords/dynamicRef.js +19 -6
- package/lib/keywords/else.js +2 -19
- package/lib/keywords/if.js +1 -9
- package/lib/keywords/itemPattern.js +5 -9
- package/lib/keywords/items.js +5 -14
- package/lib/keywords/oneOf.js +1 -33
- package/lib/keywords/patternProperties.js +7 -25
- package/lib/keywords/prefixItems.js +2 -5
- package/lib/keywords/properties.js +6 -22
- package/lib/keywords/propertyDependencies.js +1 -20
- package/lib/keywords/propertyNames.js +1 -1
- package/lib/keywords/ref.js +1 -3
- package/lib/keywords/then.js +2 -19
- package/lib/keywords/unevaluatedItems.js +44 -20
- package/lib/keywords/unevaluatedProperties.js +40 -26
- package/lib/keywords/validation.js +31 -129
- package/lib/keywords.js +30 -30
- package/package.json +1 -1
package/lib/keywords.js
CHANGED
|
@@ -35,17 +35,19 @@ export const defineVocabulary = (id, keywords) => {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const _dialects = {};
|
|
38
|
-
const _allowUnknownKeywords = {};
|
|
39
|
-
const _persistentDialects = {};
|
|
40
38
|
|
|
41
|
-
export const getKeywordId = (keyword, dialectId) =>
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
export const getKeywordId = (keyword, dialectId) => {
|
|
40
|
+
const dialect = getDialect(dialectId);
|
|
41
|
+
return dialect.keywords[keyword]
|
|
42
|
+
?? ((dialect.allowUnknownKeywords || keyword.startsWith("x-"))
|
|
43
|
+
? `https://json-schema.org/keyword/unknown#${keyword}`
|
|
44
|
+
: undefined);
|
|
45
|
+
};
|
|
44
46
|
|
|
45
47
|
export const getKeywordName = (dialectId, keywordId) => {
|
|
46
48
|
const dialect = getDialect(dialectId);
|
|
47
|
-
for (const keyword in dialect) {
|
|
48
|
-
if (dialect[keyword] === keywordId) {
|
|
49
|
+
for (const keyword in dialect.keywords) {
|
|
50
|
+
if (dialect.keywords[keyword] === keywordId) {
|
|
49
51
|
return keyword;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -62,33 +64,31 @@ const getDialect = (dialectId) => {
|
|
|
62
64
|
export const hasDialect = (dialectId) => dialectId in _dialects;
|
|
63
65
|
|
|
64
66
|
export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false, isPersistent = true) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
} else if (!allowUnknownKeywords || isRequired) {
|
|
81
|
-
delete _dialects[dialectId];
|
|
82
|
-
delete _allowUnknownKeywords[dialectId];
|
|
83
|
-
delete _persistentDialects[dialectId];
|
|
84
|
-
throw Error(`Unrecognized vocabulary: ${vocabularyId}. You can define this vocabulary with the 'defineVocabulary' function.`);
|
|
67
|
+
_dialects[dialectId] = {
|
|
68
|
+
keywords: {},
|
|
69
|
+
allowUnknownKeywords: allowUnknownKeywords,
|
|
70
|
+
persistentDialects: _dialects[dialectId]?.persistentDialects || isPersistent
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
for (const vocabularyId in dialect) {
|
|
74
|
+
if (vocabularyId in _vocabularies) {
|
|
75
|
+
for (const keyword in _vocabularies[vocabularyId]) {
|
|
76
|
+
let keywordId = _vocabularies[vocabularyId][keyword];
|
|
77
|
+
if (!(keywordId in _keywords) && !dialect[vocabularyId]) {
|
|
78
|
+
// Allow keyword to be ignored
|
|
79
|
+
keywordId = `https://json-schema.org/keyword/unknown#${keyword}`;
|
|
80
|
+
}
|
|
81
|
+
_dialects[dialectId].keywords[keyword] = keywordId;
|
|
85
82
|
}
|
|
86
|
-
})
|
|
83
|
+
} else if (!allowUnknownKeywords || dialect[vocabularyId]) {
|
|
84
|
+
delete _dialects[dialectId];
|
|
85
|
+
throw Error(`Unrecognized vocabulary: ${vocabularyId}. You can define this vocabulary with the 'defineVocabulary' function.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
87
88
|
};
|
|
88
89
|
|
|
89
90
|
export const unloadDialect = (dialectId) => {
|
|
90
|
-
if (!
|
|
91
|
-
delete _allowUnknownKeywords[dialectId];
|
|
91
|
+
if (!_dialects[dialectId]?.persistentDialects) {
|
|
92
92
|
delete _dialects[dialectId];
|
|
93
93
|
}
|
|
94
94
|
};
|
package/package.json
CHANGED