diff --git a/lib/core.js b/lib/core.js index a81e972..4916802 100644 --- a/lib/core.js +++ b/lib/core.js @@ -43,7 +43,7 @@ subscribe("validate.metaValidate", async (_message, schema) => { // Compile if (!(schema.document.dialectId in metaValidators)) { - const metaSchema = await getSchema(schema.document.dialectId); + const metaSchema = await getSchema(schema.document.dialectId, schema); const compiledSchema = await compile(metaSchema); metaValidators[schema.document.dialectId] = interpret(compiledSchema); } diff --git a/lib/schema.js b/lib/schema.js index 3850b13..57a0145 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -22,13 +22,15 @@ const schemaRegistry = {}; export const getSchema = async (uri, browser = undefined) => { if (!browser) { browser = { _cache: {} }; + } - for (const uri in schemaRegistry) { + for (const uri in schemaRegistry) { + if (!(uri in browser._cache)) { browser._cache[uri] = schemaRegistry[uri]; } } - const schema = await browserGet(uri, browser); + const schema = await browserGet(uri, { ...browser }); if (typeof schema.document.dialectId !== "string") { throw Error(`The document at ${schema.document.baseUri} is not a schema.`); }