Skip to content

refactor: move out the loadTemplateConfig from Gigantic generator.js #1584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ItsRoy69
Copy link

@ItsRoy69 ItsRoy69 commented May 29, 2025

Description

  • Moved the loadTemplateConfig function to separate file for clean code.
  • Renamed and moved the validation function inside template config

Related issue(s)
Resolves #1582

Summary by CodeRabbit

  • Refactor

    • Streamlined template configuration loading in generators for improved maintainability without changing user experience.
  • Chores

    • Updated internal import paths for consistency and clarity; no impact on functionality or user experience.

Copy link

changeset-bot bot commented May 29, 2025

⚠️ No Changeset found

Latest commit: aa60016

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented May 29, 2025

"""

Walkthrough

The changes refactor the template configuration loading logic in the generator by removing internal methods from the Generator class and introducing new external asynchronous loader functions in a dedicated module. Associated import paths and test imports are updated to reflect this modularization, with no other logic or control flow changes.

Changes

Files/Paths Change Summary
apps/generator/lib/generator.js Removed internal private async methods loadTemplateConfig and loadDefaultValues; replaced with wrappers calling external implementations; updated imports accordingly.
apps/generator/lib/templateConfig/loader.js New module exporting async functions loadTemplateConfig and loadDefaultValues to load and process template configuration and default parameter values.
apps/generator/lib/templateConfig/validator.js Updated import paths for utility modules to use parent directory references.
apps/generator/test/generator.test.js Updated import paths for template config validator module in mocks and test setup.
apps/generator/test/templateConfigValidator.test.js Updated import path for validateTemplateConfig function.
apps/generator/lib/mocks/templateConfigValidator.js Updated mock import path for template config validator.

Assessment against linked issues

Objective Addressed Explanation
Move loadTemplateConfig out of generator.js into a new templateConfig/loader.js module (#1582)
Structure template config logic into templateConfig folder with validator.js and loader.js (#1582)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes identified.

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b62c242 and aa60016.

📒 Files selected for processing (1)
  • apps/generator/lib/generator.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/generator/lib/generator.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

Hey @ItsRoy69 Have you run the test by npm run test command?

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@derberg can you please start the workflow?

@ItsRoy69
Copy link
Author

ItsRoy69 commented May 30, 2025

@ItshMoh Yes, while I ran npm run test, @derberg I found issues related to other files like SendOperation.js, MessageExamples.js and AvailableOperations.js for which many cases are failing (not related to loadTemplateConfig functions), should I create a separate issue/pull request fixing these ?

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@ItsRoy69 go through these issues.
Change the path of the `templateConfigValidator' in generator.test.js and other files where it is occuring.
The path has been changed so change its path where it has occured.

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

gen_loadtemp_test_ffail_sc

here are some of the issues.
@ItsRoy69

@ItsRoy69
Copy link
Author

@ItshMoh hey, updated the path accordingly and tested out , its passing now.

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@ItsRoy69 There are also some issues in dart client. fix it.
These are not issues with the generator. It may be because of new changes.
gen_loadTEmp_dart-sc

The snapshots are obselete, generate new ones.

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@ItsRoy69 also run npm run lint after the changes.
if there is any error npm run lint:fix.
And please also go through the https://github.com/asyncapi/generator/blob/master/CONTRIBUTING.md

Signed-off-by: ItsRoy69 <[email protected]>
@ItsRoy69
Copy link
Author

npm run test

sure, will go through it , noticed many testings are failing in other files, looking into it

@ItsRoy69
Copy link
Author

ItsRoy69 commented May 30, 2025

@ItshMoh the integration issue is separate issue, I guess that can be handled in separate PR as its quite many changes required for that which is not related to template generator error

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@ItshMoh the integration issue is separate issue, I guess that can be handled in separate PR as its quite many changes required for that which is not related to template generator error

@ItsRoy69 the integration issue is not the separate issue. it is due to the changes we made in this PR. So we need to fix it here. Otherwise how is it gonna be merged?. Look for it

@ItshMoh
Copy link
Contributor

ItshMoh commented May 30, 2025

@ItsRoy69 modify the generator.test.js file. Where the tests are failing due to
gen.loadTemplateConfig and gen.loadDefaultValues these are now not in the generator class.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
apps/generator/lib/templateConfig/loader.js (3)

7-10: Fix JSDoc annotation inconsistency.

The function is marked as @private but is exported in the module. Consider either removing the @private annotation or adding appropriate public documentation.

 /**
  * Loads the template configuration.
- * @private
+ * @param {Object} context - The generator instance context (bound via .call())
  */

41-45: Fix JSDoc annotation inconsistency.

Same issue as the loadTemplateConfig function - marked as @private but exported.

 /**
  * Loads default values of parameters from template config. If value was already set as parameter it will not be
- * overriden.
- * @private
+ * overridden.
+ * @param {Object} context - The generator instance context (bound via .call())
  */

Note: Also fixed the typo "overriden" → "overridden".


46-58: Consider the context dependency design.

The functions rely heavily on this context (accessing this.templateDir, this.templateConfig, this.templateParams), which requires careful binding when called. While this maintains compatibility with the existing codebase during refactoring, consider whether a more explicit parameter-passing approach might be more maintainable long-term.

For now, the current approach is acceptable given the refactoring context.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 870e622 and cfffd89.

📒 Files selected for processing (3)
  • apps/generator/lib/generator.js (3 hunks)
  • apps/generator/lib/templateConfig/loader.js (1 hunks)
  • apps/generator/lib/templateConfig/validator.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/generator/lib/templateConfig/validator.js
  • apps/generator/lib/generator.js
🔇 Additional comments (1)
apps/generator/lib/templateConfig/loader.js (1)

11-39: Excellent refactoring approach with proper error handling.

The configuration loading logic is well-structured with appropriate fallback mechanisms:

  • Primary attempt: .ageneratorrc (YAML format)
  • Fallback: package.json with generator property
  • Graceful error handling with debug logging

The refactoring successfully extracts this logic from the main generator file while maintaining the same behavior.

Copy link

@ItsRoy69
Copy link
Author

ItsRoy69 commented May 30, 2025

Fixed the issues for which testing were failing after running npm run test, npm run lint:fix, npm run lint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: move out the loadTemplateConfig from Gigantic generator.js
2 participants