Skip to content

Commit

Permalink
don't crash if the OpenAPI spec is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney committed Oct 24, 2023
1 parent 0069e9b commit 39b1643
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/typescript-generator/generate.js
Expand Up @@ -36,6 +36,18 @@ async function buildCacheDirectory(destination) {
}
}

async function getPathsFromSpecification(specification) {
try {
return await specification.requirementAt("#/paths");
} catch (error) {
process.stderr.write(
`Could not find #/paths in the specification.\n${error}\n`,
);

return [];
}
}

// eslint-disable-next-line max-statements
export async function generate(
source,
Expand All @@ -54,9 +66,9 @@ export async function generate(

debug("created specification: $o", specification);

debug("getting reading the #/paths from the specification");
debug("reading the #/paths from the specification");

const paths = await specification.requirementAt("#/paths");
const paths = await getPathsFromSpecification(specification);

debug("got %i paths", paths.size);

Expand Down

0 comments on commit 39b1643

Please sign in to comment.