Skip to content

Commit

Permalink
fix: prevent crash if no $ref in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rosvik committed Oct 10, 2024
1 parent 6bf7b45 commit 3a0f481
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tools/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ async function readSpecification(
const spec = await readFile(join(BASE_FOLDER, `${filename}.json`));
try {
const parsed = JSON.parse(spec.toString());
const previous = ajv.getSchema(parsed['$ref']);

if (previous) {
return previous;
} else {
return ajv.compile(parsed);
if (parsed['$ref']) {
const previous = ajv.getSchema(parsed['$ref']);
if (previous) {
return previous;
}
}
return ajv.compile(parsed);
} catch (err) {
throw new Error(`Unable to load or parse ${err}`);
}
Expand Down

0 comments on commit 3a0f481

Please sign in to comment.