Skip to content

Commit

Permalink
When loading schema, if runtime is deno and schemaURL not http try lo…
Browse files Browse the repository at this point in the history
…ading as a local file
  • Loading branch information
rwblair committed Oct 17, 2024
1 parent 35306a2 commit e95a5eb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bids-validator/src/setup/loadSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ export async function loadSchema(version?: string): Promise<Schema> {
) as Schema

if (schemaUrl !== undefined) {
let jsonData = {}

Check warning on line 26 in bids-validator/src/setup/loadSchema.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/setup/loadSchema.ts#L26

Added line #L26 was not covered by tests
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))

Check warning on line 31 in bids-validator/src/setup/loadSchema.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/setup/loadSchema.ts#L28-L31

Added lines #L28 - L31 were not covered by tests

} else {
const jsonResponse = await fetch(schemaUrl)
jsonData = await jsonResponse.json()
}

Check warning on line 36 in bids-validator/src/setup/loadSchema.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/setup/loadSchema.ts#L33-L36

Added lines #L33 - L36 were not covered by tests
schema = new Proxy(
jsonData as object,
objectPathHandler,
Expand Down

0 comments on commit e95a5eb

Please sign in to comment.