@hyperjump/json-schema 1.10.0 → 1.10.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/lib/keywords.js +9 -3
- package/lib/schema.js +1 -1
- package/package.json +1 -1
package/lib/keywords.js
CHANGED
|
@@ -36,6 +36,7 @@ export const defineVocabulary = (id, keywords) => {
|
|
|
36
36
|
|
|
37
37
|
const _dialects = {};
|
|
38
38
|
const _allowUnknownKeywords = {};
|
|
39
|
+
const _persistentDialects = {};
|
|
39
40
|
|
|
40
41
|
export const getKeywordId = (keyword, dialectId) => getDialect(dialectId)?.[keyword]
|
|
41
42
|
|| (_allowUnknownKeywords[dialectId] || keyword.startsWith("x-"))
|
|
@@ -60,8 +61,9 @@ const getDialect = (dialectId) => {
|
|
|
60
61
|
|
|
61
62
|
export const hasDialect = (dialectId) => dialectId in _dialects;
|
|
62
63
|
|
|
63
|
-
export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false) => {
|
|
64
|
+
export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false, isPersistent = true) => {
|
|
64
65
|
_allowUnknownKeywords[dialectId] = allowUnknownKeywords;
|
|
66
|
+
_persistentDialects[dialectId] = _persistentDialects[dialectId] || isPersistent;
|
|
65
67
|
|
|
66
68
|
_dialects[dialectId] = {};
|
|
67
69
|
Object.entries(dialect)
|
|
@@ -77,12 +79,16 @@ export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false) =>
|
|
|
77
79
|
});
|
|
78
80
|
} else if (!allowUnknownKeywords || isRequired) {
|
|
79
81
|
delete _dialects[dialectId];
|
|
82
|
+
delete _allowUnknownKeywords[dialectId];
|
|
83
|
+
delete _persistentDialects[dialectId];
|
|
80
84
|
throw Error(`Unrecognized vocabulary: ${vocabularyId}. You can define this vocabulary with the 'defineVocabulary' function.`);
|
|
81
85
|
}
|
|
82
86
|
});
|
|
83
87
|
};
|
|
84
88
|
|
|
85
89
|
export const unloadDialect = (dialectId) => {
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
if (!_persistentDialects[dialectId]) {
|
|
91
|
+
delete _allowUnknownKeywords[dialectId];
|
|
92
|
+
delete _dialects[dialectId];
|
|
93
|
+
}
|
|
88
94
|
};
|
package/lib/schema.js
CHANGED
|
@@ -93,7 +93,7 @@ export const buildSchemaDocument = (schema, id, dialectId, embedded = {}) => {
|
|
|
93
93
|
const allowUnknownKeywords = schema[vocabularyToken]["https://json-schema.org/draft/2019-09/vocab/core"]
|
|
94
94
|
|| schema[vocabularyToken]["https://json-schema.org/draft/2020-12/vocab/core"];
|
|
95
95
|
|
|
96
|
-
loadDialect(id, schema[vocabularyToken], allowUnknownKeywords);
|
|
96
|
+
loadDialect(id, schema[vocabularyToken], allowUnknownKeywords, false);
|
|
97
97
|
delete schema[vocabularyToken];
|
|
98
98
|
}
|
|
99
99
|
|
package/package.json
CHANGED