From e95a5ebc3f949809703a5fb78f5f0d7e138f3be0 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Thu, 17 Oct 2024 10:21:37 -0500 Subject: [PATCH] When loading schema, if runtime is deno and schemaURL not http try loading as a local file --- bids-validator/src/setup/loadSchema.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bids-validator/src/setup/loadSchema.ts b/bids-validator/src/setup/loadSchema.ts index d8b45f56f..36b0334c7 100644 --- a/bids-validator/src/setup/loadSchema.ts +++ b/bids-validator/src/setup/loadSchema.ts @@ -23,9 +23,17 @@ export async function loadSchema(version?: string): Promise { ) as Schema if (schemaUrl !== undefined) { + let jsonData = {} try { - const jsonResponse = await fetch(schemaUrl) - const jsonData = await jsonResponse.json() + if (typeof Deno !== 'undefined' && !schemaUrl.match(/http(s)?:\/\//)) { + const decoder = new TextDecoder("utf-8"); + const data = await Deno.readFile(schemaUrl); + jsonData = JSON.parse(decoder.decode(data)) + + } else { + const jsonResponse = await fetch(schemaUrl) + jsonData = await jsonResponse.json() + } schema = new Proxy( jsonData as object, objectPathHandler,