Skip to content

Commit 88bc2c2

Browse files
fix: replace ?. with old style falsy check (#302)
* replace ?. with old style falsy check * chore: reformat
1 parent 9b2dd8d commit 88bc2c2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

filters/all.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,10 @@ function getExtraImports(asyncapi) {
568568
function getPayloadPackage(pubOrSub) {
569569
let fullPackagePath;
570570
if (!pubOrSub.hasMultipleMessages()) {
571-
const payload = pubOrSub.message()?.payload();
571+
let payload;
572+
if (pubOrSub.message()) {
573+
payload = pubOrSub.message().payload();
574+
}
572575
if (payload) {
573576
const type = payload.type();
574577
const importName = payload.ext('x-parser-schema-id');

hooks/pre-process.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ function setSchemaIdsForFileName(asyncapi) {
1313
classNameForGenerator = parserSchemaId ? parserSchemaId : _.camelCase(schema.$id().substring(schema.$id().lastIndexOf('/') + 1));
1414

1515
if (classNameForGenerator === 'items') {
16-
const parentSchema = schema.options?.parent;
17-
const parentSchemaItems = parentSchema?.items();
18-
if (parentSchemaItems?._json?.$id === schema.$id()) {
16+
let parentSchema;
17+
if (schema.options) {
18+
parentSchema = schema.options.parent;
19+
}
20+
let parentSchemaItems;
21+
if (parentSchema) {
22+
parentSchemaItems = parentSchema.items();
23+
}
24+
let parentSchemaItemsId;
25+
if (parentSchemaItems && parentSchemaItems._json) {
26+
parentSchemaItemsId = parentSchemaItems._json.$id;
27+
}
28+
if (parentSchemaItemsId === schema.$id()) {
1929
const parentParserSchemaId = parentSchema.ext('x-parser-schema-id');
2030
classNameForGenerator = parentParserSchemaId ? parentParserSchemaId : _.camelCase(parentSchema.$id().substring(parentSchema.$id().lastIndexOf('/') + 1));
2131
// 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.

0 commit comments

Comments
 (0)