From 88bc2c28d36e1bb2ab4320cc14b97a944cbcdd23 Mon Sep 17 00:00:00 2001 From: Cameron Rushton Date: Fri, 28 Oct 2022 13:37:06 -0400 Subject: [PATCH] fix: replace ?. with old style falsy check (#302) * replace ?. with old style falsy check * chore: reformat --- filters/all.js | 5 ++++- hooks/pre-process.js | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) 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.