Fix modify-schema crash on null allOf value

This commit is contained in:
Bill Thornton 2024-09-23 16:11:53 -04:00
parent 20c0699a5a
commit a40903984f

View File

@ -1,7 +1,7 @@
/**
* This script works around an issue with the openapi generator
* not parsing allOf types correctly.
*
*
* Originally part of the jellyfin-client-axios project:
* https://github.com/jellyfin/jellyfin-client-axios/blob/dfadff9b0b8749a04fb21d298b86624b20db1e5a/scripts/modifySchema.mjs
*/
@ -11,10 +11,10 @@ import fs from 'fs/promises';
let txt = await fs.readFile(file);
const json = JSON.parse(txt, (_, value) => {
// Remove all "allOf" instances, this removes nullability/descriptions
if (typeof value === 'object' && 'allOf' in value && value.allOf.length === 1) {
if (!!value && typeof value === 'object' && 'allOf' in value && value.allOf.length === 1) {
return value.allOf[0];
}
return value;
});