Skip to content

Commit

Permalink
Filter undefined items due to transient parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata committed Jul 13, 2022
1 parent 69e5a50 commit 70b31c4
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,39 @@ export async function processOpenapiFiles(
sidebarOptions: SidebarOptions
): Promise<[ApiMetadata[], TagObject[]]> {
const promises = files.map(async (file) => {
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
const itemsObjectsArray = processedFile[0].map((item) => ({
...item,
}));
const tags = processedFile[1];
return [itemsObjectsArray, tags];
if (file.data !== undefined) {
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
const itemsObjectsArray = processedFile[0].map((item) => ({
...item,
}));
const tags = processedFile[1];
return [itemsObjectsArray, tags];
}
console.warn(
chalk.yellow(
`WARNING: the following OpenAPI spec returned undefined: ${file.source}`
)
);
return [];
});
const metadata = await Promise.all(promises);
const items = metadata
.map(function (x) {
return x[0];
})
.flat();
const tags = metadata.map(function (x) {
return x[1];
});
.flat()
.filter(function (x) {
// Remove undefined items due to transient parsing errors
return x !== undefined;
});
const tags = metadata
.map(function (x) {
return x[1];
})
.filter(function (x) {
// Remove undefined tags due to transient parsing errors
return x !== undefined;
});
return [items as ApiMetadata[], tags as TagObject[]];
}

Expand Down

0 comments on commit 70b31c4

Please sign in to comment.