Skip to content

Commit

Permalink
fix: replace ?. with old style falsy check (#302)
Browse files Browse the repository at this point in the history
* replace ?. with old style falsy check

* chore: reformat
  • Loading branch information
CameronRushton authored Oct 28, 2022
1 parent 9b2dd8d commit 88bc2c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 13 additions & 3 deletions hooks/pre-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 88bc2c2

Please sign in to comment.