diff --git a/src/load.ts b/src/load.ts index 7df6c2344..c3aa0884c 100644 --- a/src/load.ts +++ b/src/load.ts @@ -88,18 +88,18 @@ function parseHttpHeaders(httpHeaders: Record): Headers { interface LoadOptions extends GlobalContext { rootURL: URL; schemas: SchemaMap; + urlCache?: Set; // URL cache (prevent URLs from being loaded over and over) httpHeaders?: Headers; httpMethod?: string; } -// temporary cache for load() -let urlCache = new Set(); // URL cache (prevent URLs from being loaded over and over) - /** Load a schema from local path or remote URL */ export default async function load( schema: URL | PartialSchema, options: LoadOptions ): Promise<{ [url: string]: PartialSchema }> { + const urlCache = options.urlCache || new Set(); + const isJSON = schema instanceof URL === false; // if this is dynamically-passed-in JSON, we’ll have to change a few things let schemaID = isJSON ? new URL(VIRTUAL_JSON_URL).href : (schema.href as string); @@ -182,7 +182,7 @@ export default async function load( const nextURL = isRemoteURL ? new URL(refURL) : new URL(slash(refURL), schema as URL); refPromises.push( - load(nextURL, options).then((subschemas) => { + load(nextURL, { ...options, urlCache }).then((subschemas) => { for (const subschemaURL of Object.keys(subschemas)) { schemas[subschemaURL] = subschemas[subschemaURL]; }