diff --git a/filters/all.js b/filters/all.js index 70492b3b..03344f79 100644 --- a/filters/all.js +++ b/filters/all.js @@ -568,7 +568,10 @@ function getExtraImports(asyncapi) { function getPayloadPackage(pubOrSub) { let fullPackagePath; if (!pubOrSub.hasMultipleMessages()) { - const payload = pubOrSub.message()?.payload(); + let payload; + if (pubOrSub.message()) { + payload = pubOrSub.message().payload(); + } if (payload) { const type = payload.type(); const importName = payload.ext('x-parser-schema-id'); diff --git a/hooks/pre-process.js b/hooks/pre-process.js index bcf388be..468f983b 100644 --- a/hooks/pre-process.js +++ b/hooks/pre-process.js @@ -13,9 +13,19 @@ function setSchemaIdsForFileName(asyncapi) { classNameForGenerator = parserSchemaId ? parserSchemaId : _.camelCase(schema.$id().substring(schema.$id().lastIndexOf('/') + 1)); if (classNameForGenerator === 'items') { - const parentSchema = schema.options?.parent; - const parentSchemaItems = parentSchema?.items(); - if (parentSchemaItems?._json?.$id === schema.$id()) { + let parentSchema; + if (schema.options) { + parentSchema = schema.options.parent; + } + let parentSchemaItems; + if (parentSchema) { + parentSchemaItems = parentSchema.items(); + } + let parentSchemaItemsId; + if (parentSchemaItems && parentSchemaItems._json) { + parentSchemaItemsId = parentSchemaItems._json.$id; + } + if (parentSchemaItemsId === schema.$id()) { const parentParserSchemaId = parentSchema.ext('x-parser-schema-id'); classNameForGenerator = parentParserSchemaId ? parentParserSchemaId : _.camelCase(parentSchema.$id().substring(parentSchema.$id().lastIndexOf('/') + 1)); // If we come across this schema later in the code generator, we'll know to rename it to its parent because the proper settings will be set in the model class.