Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions apps/generator/lib/conditionalGeneration.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const log = require('loglevel');
const logMessage = require('./logMessages');
const jmespath = require('jmespath');
Expand All @@ -24,6 +26,11 @@ async function isGenerationConditionMet (
const config = Object.keys(conditionFilesGeneration).length > 0
? conditionFilesGeneration
: conditionalGeneration;
if (config.subject) {
return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
} else if (config.parameter) {
return conditionalParameterGeneration(templateConfig, matchedConditionPath, templateParams);
}
Comment on lines +29 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent indentation in the early-branch block.

The if/else if block mixes 4-space and 2-space indentation and has a double space after templateConfig, on line 32. If the dead code below is removed (see other comment), this block should use consistent project indentation.

Proposed fix (assuming 2-space project indent)
-    if (config.subject) {
-  return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
-  } else if (config.parameter) {
-  return conditionalParameterGeneration(templateConfig,   matchedConditionPath, templateParams);
-  }
+  if (config.subject) {
+    return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
+  } else if (config.parameter) {
+    return conditionalParameterGeneration(templateConfig, matchedConditionPath, templateParams);
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (config.subject) {
return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
} else if (config.parameter) {
return conditionalParameterGeneration(templateConfig, matchedConditionPath, templateParams);
}
if (config.subject) {
return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
} else if (config.parameter) {
return conditionalParameterGeneration(templateConfig, matchedConditionPath, templateParams);
}
🤖 Prompt for AI Agents
In `@apps/generator/lib/conditionalGeneration.js` around lines 29 - 33, The
if/else-if branch uses inconsistent indentation and an extra space after
templateConfig; update the block around the config check so indentation matches
the project's 2-space style and remove the double space in the call to
conditionalParameterGeneration(templateConfig, matchedConditionPath,
templateParams); ensure the calls to
conditionalSubjectGeneration(asyncapiDocument, templateConfig,
matchedConditionPath, templateParams) and conditionalParameterGeneration(...)
are indented consistently with surrounding code and use single spaces after
commas.


const subject = config?.subject;

Expand All @@ -42,10 +49,11 @@ async function isGenerationConditionMet (
return conditionalSubjectGeneration(
asyncapiDocument,
templateConfig,
matchedConditionPath
matchedConditionPath,
templateParams // FIX: was missing in original, caused TypeError on templateParams.server
);
}
return conditionalParameterGeneration(templateConfig,matchedConditionPath,templateParams);
return conditionalParameterGeneration(templateConfig, matchedConditionPath, templateParams);
}
};

Expand All @@ -64,7 +72,11 @@ async function conditionalParameterGeneration(templateConfig, matchedConditionPa
const conditionalGenerationConfig = templateConfig.conditionalGeneration?.[matchedConditionPath];
const parameterName = conditionalGenerationConfig.parameter;
const parameterValue = templateParams[parameterName];
return validateStatus(parameterValue, matchedConditionPath, templateConfig);
if (parameterValue == null) {
log.debug(logMessage.relativeSourceFileNotGenerated(matchedConditionPath, parameterName));
return false;
}
return true;
}

/**
Expand All @@ -77,15 +89,6 @@ async function conditionalParameterGeneration(templateConfig, matchedConditionPa
* @param {Object} templateParams - The parameters passed to the generator, usually user input or default values.
* @returns {Boolean} - Returns `true` if the file should be included; `false` if it should be skipped.
*/
async function conditionalFilesGenerationDeprecatedVersion (
asyncapiDocument,
templateConfig,
matchedConditionPath,
templateParams
) {
return conditionalSubjectGeneration(asyncapiDocument, templateConfig, matchedConditionPath, templateParams);
};

/**
* Determines whether a file should be conditionally included based on the provided subject expression
* and optional validation logic defined in the template configuration.
Expand All @@ -101,7 +104,6 @@ async function conditionalSubjectGeneration (
templateConfig,
matchedConditionPath,
templateParams

) {
const fileCondition = templateConfig.conditionalGeneration?.[matchedConditionPath] || templateConfig.conditionalFiles?.[matchedConditionPath];
if (!fileCondition || !fileCondition.subject) {
Expand All @@ -115,8 +117,7 @@ async function conditionalSubjectGeneration (
server: server ? server.json() : undefined,
},
}, subject);

if (!source) {
if (source == null) {
log.debug(logMessage.relativeSourceFileNotGenerated(matchedConditionPath, subject));
return false;
}
Expand Down
Loading