Skip to content

refactor: remove old FileHeaderInfo and add shared version for both JS and Python templates #1519

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 19 commits into
base: master
Choose a base branch
from

Conversation

AdeebaNizam404
Copy link
Contributor

@AdeebaNizam404 AdeebaNizam404 commented Apr 29, 2025

Description

Removed the old FileHeaderInfo.js and FileHeaderInfo.test.js from the JavaScript client folders.

Added a new, shared version of FileHeaderInfo.js in the components/src/components directory.

Added the corresponding test file FileHeaderInfo.test.js in the components/test/components directory.

Updated both the JavaScript (client.js.js) and Python (client.py.js) templates to use the new shared FileHeaderInfo.js.

This ensures that the same FileHeaderInfo.js is used in both the JavaScript and Python client templates.

Testing:

Verified that the new FileHeaderInfo.js works correctly in both templates (client.js.js and client.py.js).

All tests pass successfully.
Screenshot 2025-04-29 122137

Screenshot 2025-04-29 121636

Related issue(s)

Fixes #1447

Summary by CodeRabbit

  • New Features

    • Introduced a reusable file header component that formats API and server information for different programming languages.
  • Refactor

    • Centralized the file header component for easier maintenance and consistency across JavaScript and Python templates.
    • Updated usage of the file header component to specify the target language.
    • Removed local file header components from JavaScript and Python websocket client templates.
  • Tests

    • Updated tests to support the new language prop in the file header component.
  • Chores

    • Added a new Git submodule for generator tooling with corresponding .gitignore configuration.
    • Updated package dependencies to include the latest generator packages and utilities.

Copy link

coderabbitai bot commented Apr 29, 2025

"""

Walkthrough

A new shared FileHeaderInfo React component has been introduced in the components package, supporting both JavaScript and Python comment styles via a language prop. The component is now exported from the central index for reuse. Previous, language-specific implementations of FileHeaderInfo in the websocket client templates for JavaScript and Python have been removed. Imports in the respective template files have been updated to reference the new shared component, and the language prop is now passed accordingly. Related tests have been updated to use the new prop.

Changes

Files / Paths Change Summary
packages/components/src/components/FileHeaderInfo.js, packages/components/src/index.js Introduced new FileHeaderInfo component with language prop and exported it from the package index.
packages/templates/clients/websocket/javascript/components/FileHeaderInfo.js,
packages/templates/clients/websocket/python/components/FileHeaderInfo.js
Removed old, language-specific FileHeaderInfo components from template directories.
packages/templates/clients/websocket/javascript/template/client.js.js,
packages/templates/clients/websocket/python/template/client.py.js
Updated imports to use the shared FileHeaderInfo component and added the language prop.
packages/components/test/components/FileHeaderInfo.test.js Updated tests to include the language prop in FileHeaderInfo usage.

Sequence Diagram(s)

sequenceDiagram
    participant TemplateClient as Template Client (JS/Python)
    participant GeneratorComponents as @asyncapi/generator-components
    participant FileHeaderInfo as FileHeaderInfo

    TemplateClient->>GeneratorComponents: import { FileHeaderInfo }
    TemplateClient->>FileHeaderInfo: <FileHeaderInfo info, server, language="js|python" />
    FileHeaderInfo-->>TemplateClient: Rendered header block with appropriate comment style
Loading

Assessment against linked issues

Objective Addressed Explanation
Add FileHeaderInfo.test.js for python websocket client, including conditional logic coverage (#1447) No new test file specifically for the Python websocket client was added; only existing tests were updated.

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • magicmatatjahu
  • jonaslagoni
  • asyncapi-bot-eve
  • derberg

Poem

Hopping through code with a twitch of my nose,
I see headers now shared, as the new standard goes!
No more two burrows for Python and JS,
One cozy component—oh what a success!
With slashes or hashes, your docs will delight,
This bunny approves—everything’s right! 🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8022cf6 and fa75b98.

⛔ Files ignored due to path filters (1)
  • packages/templates/clients/websocket/javascript/test/__snapshots__/integration.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • packages/components/test/components/FileHeaderInfo.test.js (1 hunks)
  • packages/templates/clients/websocket/javascript/template/client.js.js (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/templates/clients/websocket/javascript/template/client.js.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/test/components/FileHeaderInfo.test.js
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Acceptance tests for generated templates
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test NodeJS PR - windows-latest
✨ 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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

changeset-bot bot commented Apr 29, 2025

⚠️ No Changeset found

Latest commit: fa75b98

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

@AdeebaNizam404 AdeebaNizam404 changed the title "Refactor: Remove old FileHeaderInfo and add shared version for both JS and Python templates refactor: Remove old FileHeaderInfo and add shared version for both JS and Python templates Apr 29, 2025
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: 2

🧹 Nitpick comments (1)
packages/components/src/components/FileHeaderInfo.js (1)

8-14: Consider using a more extensible approach for language-specific formatting.

While the current implementation works for JavaScript and Python, future language support might be limited by the if/else structure.

Consider using an object map for comment styles, which would be more maintainable as you add more languages:

- // Decide comment style based on language
- if (language === 'python') {
-   commentChar = '#';
-   line = commentChar + ' ' + '/'.repeat(70);
- } else {
-   commentChar = '//';
-   line = commentChar + '/'.repeat(70);
- }
+ // Define comment styles for different languages
+ const commentStyles = {
+   python: { char: '#', separator: ' ' },
+   javascript: { char: '//', separator: '' },
+   // Add more languages as needed
+ };
+ 
+ // Default to JavaScript style if language not found
+ const style = commentStyles[language] || commentStyles.javascript;
+ commentChar = style.char;
+ line = commentChar + style.separator + '/'.repeat(70);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca08cf0 and 4d041bf.

⛔ Files ignored due to path filters (3)
  • packages/templates/clients/websocket/javascript/test/__snapshots__/integration.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/javascript/test/components/__snapshots__/FileHeaderInfo.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/python/test/__snapshots__/integration.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • packages/components/src/components/FileHeaderInfo.js (1 hunks)
  • packages/components/src/index.js (1 hunks)
  • packages/components/test/components/FileHeaderInfo.test.js (1 hunks)
  • packages/templates/clients/websocket/javascript/components/FileHeaderInfo.js (0 hunks)
  • packages/templates/clients/websocket/javascript/template/client.js.js (2 hunks)
  • packages/templates/clients/websocket/python/components/FileHeaderInfo.js (0 hunks)
  • packages/templates/clients/websocket/python/template/client.py.js (2 hunks)
💤 Files with no reviewable changes (2)
  • packages/templates/clients/websocket/javascript/components/FileHeaderInfo.js
  • packages/templates/clients/websocket/python/components/FileHeaderInfo.js
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/components/test/components/FileHeaderInfo.test.js (1)
packages/components/src/components/FileHeaderInfo.js (1)
  • FileHeaderInfo (3-45)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test generator as dependency with Node 18
🔇 Additional comments (8)
packages/components/src/components/FileHeaderInfo.js (1)

1-45: The implementation looks good, with a clean approach to handling different comment styles.

This new shared component correctly implements conditional comment styling based on the language prop, using '#' for Python and '//' for other languages. The component structure is well-organized and follows React best practices with functional components and clear prop usage.

packages/components/src/index.js (1)

2-2: Export of the shared component looks good.

The new FileHeaderInfo component is properly exported from the index file, making it available for consumption by other packages.

packages/templates/clients/websocket/javascript/template/client.js.js (3)

3-3: Import correctly updated to use the shared component.

The import has been properly changed to reference the shared component from the @asyncapi/generator-components package instead of a local relative path.


18-18: Language prop correctly added to the component.

The language="javascript" prop is properly added to the FileHeaderInfo component to ensure JavaScript-style comments are used.


15-19:

✅ Verification successful

Verify consistency between implementation and usage.

The component implementation checks for language === 'python', but here you're passing language="javascript". This works because the implementation uses an else condition for non-Python languages, but it might be clearer to match exactly.

Check that the language string values used in templates match exactly with the conditions in the component:


🏁 Script executed:

#!/bin/bash
# Show how the FileHeaderInfo component is used in all templates
echo "FileHeaderInfo usage in templates:"
rg -A 3 "FileHeaderInfo" --glob "*.js.js" packages/templates/

# Compare with the conditions in the component
echo -e "\nFileHeaderInfo implementation:"
cat packages/components/src/components/FileHeaderInfo.js | grep -A 5 "language ==="

Length of output: 1318


Consistency Confirmed: ‘javascript’ Is Handled by the Else Branch
The FileHeaderInfo component only special-cases language === 'python'; all other values—including "javascript"—fall into the else branch and use //. No changes are required unless you’d prefer to add an explicit language === 'javascript' check for clarity.

packages/components/test/components/FileHeaderInfo.test.js (1)

1-40: Overall test structure looks good.

The test loads a fixture, parses an AsyncAPI document, and renders the component with different server configurations. The snapshots approach is appropriate for testing React components.

packages/templates/clients/websocket/python/template/client.py.js (2)

3-3: Great work on the import refactoring!

The change from a local import to using the shared component from @asyncapi/generator-components is a good improvement. This promotes better code reuse across the codebase.


16-20: Well implemented component usage with language prop.

The FileHeaderInfo component is now properly used with the new language="python" prop, allowing the shared component to render the appropriate Python-style comments. This is a good refactoring that reduces duplication while maintaining language-specific functionality.

@AdeebaNizam404 AdeebaNizam404 changed the title refactor: Remove old FileHeaderInfo and add shared version for both JS and Python templates refactor: remove old FileHeaderInfo and add shared version for both JS and Python templates Apr 29, 2025
@derberg
Copy link
Member

derberg commented Apr 29, 2025

I guess it should be closed in favour of #1520 ?

import path from 'path';
import { render } from '@asyncapi/generator-react-sdk';
import { Parser, fromFile } from '@asyncapi/parser';
import { FileHeaderInfo } from '../../components/FileHeaderInfo';
Copy link
Contributor

@Adi-204 Adi-204 Apr 30, 2025

Choose a reason for hiding this comment

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

@AdeebaNizam404 change path ../../components/FileHeaderInfo to ../../src/components/FileHeaderInfo.js

import { FileHeaderInfo } from '../../components/FileHeaderInfo';

const parser = new Parser();
const asyncapi_websocket_query = path.resolve(__dirname, '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
Copy link
Contributor

Choose a reason for hiding this comment

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

Change path from
../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml
to
../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml

also update snapshot with cmd npm run test:update.

Comment on lines 3 to 15
export function FileHeaderInfo({ info, server, language }) {
let commentChar;
let line;

// Decide comment style based on language
if (language === 'python') {
commentChar = '#';
line = commentChar + ' ' + '/'.repeat(70);
} else {
commentChar = '//';
line = commentChar + '/'.repeat(70);
}

Copy link
Member

Choose a reason for hiding this comment

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

please modify it in a similar way to https://github.com/asyncapi/generator/blob/master/packages/components/src/components/models.js

since now it is part of a components library, we need to make sure:

  • it is easy to extend with more languages, so language maping is needed instead of such simple if/else
  • proper jsdocs with @typedef to make sure that whoever uses such component in their code, they get nice docs rendered

example of what we got when we use Model component I referred you to

Screenshot 2025-04-30 at 12 37 31

@derberg derberg moved this to In Progress in Maintainers work Apr 30, 2025
@Adi-204
Copy link
Contributor

Adi-204 commented May 14, 2025

@AdeebaNizam404 tests are failing because snapshots are not updated just run npm run test:update.

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 (1)
package.json (1)

47-50: Ensure lockfile is updated
After adding "@asyncapi/generator", please run npm install and commit the updated package-lock.json (or shrinkwrap file) to keep installs reproducible.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 35653e1 and 8022cf6.

⛔ Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json
  • packages/templates/clients/websocket/javascript/test/__snapshots__/integration.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/python/test/__snapshots__/integration.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/templates/clients/websocket/dart/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/templates/clients/websocket/dart/package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Acceptance tests for generated templates

Comment on lines +47 to +50
],
"dependencies": {
"@asyncapi/generator": "^2.6.0"
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical: Confirm correct package and scope for new dependency
The root package.json is marked private and uses workspaces, so hoisting a runtime dependency here may be unnecessary.

  1. Should this dependency instead live in packages/components or in each template’s own package.json?
  2. The shared component import in your templates uses @asyncapi/generator-components; was adding @asyncapi/generator intentional, or did you mean to depend on @asyncapi/generator-components?

🏁 Script executed:

#!/bin/bash
set -e

echo "=== Root package.json metadata ==="
jq '{ private, workspaces, dependencies }' package.json || cat package.json | sed -n '1,20p'

echo
echo "=== Workspace package.json files ==="
fd -t f -e package.json

echo
echo "=== Search for '@asyncapi/generator' in codebase ==="
rg -n "@asyncapi/generator"

echo
echo "=== Search for '@asyncapi/generator-components' in codebase ==="
rg -n "@asyncapi/generator-components"

Length of output: 28806


Critical: Remove or relocate @asyncapi/generator from the root package.json

The root manifest is private and only orchestrates workspaces—hoisting a runtime dependency here duplicates declarations in the actual consumers.

• File: package.json (lines 47–50): drop the "@asyncapi/generator": "^2.6.0" entry
• Each template under packages/templates/** and the apps/generator workspace already declares @asyncapi/generator (currently "*"). To lock on ^2.6.0, update those entries and remove the wildcard.
• If you intended to hoist to root, instead remove the per-template declarations and document the centralized version.
• Finally, confirm you meant the CLI/runtime package (@asyncapi/generator) and not the shared components library (@asyncapi/generator-components).

🤖 Prompt for AI Agents
In package.json lines 47 to 50, remove the "@asyncapi/generator" dependency from
the root manifest because it is private and uses workspaces, so runtime
dependencies should be declared in the actual consuming packages. Instead,
update the "@asyncapi/generator" version from "*" to "^2.6.0" in each template's
package.json under packages/templates/** and in apps/generator. Confirm that you
intended to depend on "@asyncapi/generator" (the CLI/runtime package) and not
"@asyncapi/generator-components" before making these changes.

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

many changes not related to this PR showed up in here, like git module, git ignore and others - for example "@asyncapi/generator": "^2.6.0" should not be there in package.json

please go through your PR and changed files and make sure in PR we only see files modified to solve this PR. Also once you cleaup package.json also make sure package-lock files are also not modified in this PR

Copy link

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

Successfully merging this pull request may close these issues.

[Test]: Add FileHeaderInfo.test.js for python websocket client
3 participants