adapt-schemas 3.1.0 → 3.1.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/Schemas.js +20 -0
- package/package.json +1 -1
package/lib/Schemas.js
CHANGED
|
@@ -110,6 +110,12 @@ class Schemas extends EventEmitter {
|
|
|
110
110
|
* Empties the schema registry (with the exception of the base schema)
|
|
111
111
|
*/
|
|
112
112
|
resetSchemaRegistry () {
|
|
113
|
+
// Remove previously registered schemas from AJV instances
|
|
114
|
+
for (const name of Object.keys(this.schemas)) {
|
|
115
|
+
for (const v of [this.validator, this.validatorWithDefaults]) {
|
|
116
|
+
if (v.getSchema(name)) v.removeSchema(name)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
113
119
|
this.schemas = {
|
|
114
120
|
base: this.createSchema(path.resolve(__dirname, BASE_SCHEMA_PATH), { enableCache: true })
|
|
115
121
|
}
|
|
@@ -224,6 +230,16 @@ class Schemas extends EventEmitter {
|
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
this.schemas[schema.name] = schema
|
|
233
|
+
|
|
234
|
+
// AJV's sync compile() can only resolve $refs against schemas in its internal store to allow `$ref: "schemaName`"
|
|
235
|
+
// Note we only add simple schemas (no $merge/$patch)
|
|
236
|
+
if (!schema.raw.$merge && !schema.raw.$patch) {
|
|
237
|
+
for (const v of [this.validator, this.validatorWithDefaults]) {
|
|
238
|
+
if (v.getSchema(schema.name)) v.removeSchema(schema.name)
|
|
239
|
+
v.addSchema(schema.raw, schema.name)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
227
243
|
this.schemaExtensions?.[schema.name]?.forEach(s => schema.addExtension(s))
|
|
228
244
|
|
|
229
245
|
if (schema.raw.$patch) {
|
|
@@ -242,6 +258,10 @@ class Schemas extends EventEmitter {
|
|
|
242
258
|
if (this.schemas[name]) {
|
|
243
259
|
delete this.schemas[name]
|
|
244
260
|
}
|
|
261
|
+
// Remove from AJV instances
|
|
262
|
+
for (const v of [this.validator, this.validatorWithDefaults]) {
|
|
263
|
+
if (v.getSchema(name)) v.removeSchema(name)
|
|
264
|
+
}
|
|
245
265
|
// Remove schema from any extensions lists
|
|
246
266
|
Object.entries(this.schemaExtensions).forEach(([base, extensions]) => {
|
|
247
267
|
this.schemaExtensions[base] = extensions.filter(s => s !== name)
|