Skip to content

refactor: deduplicate JSDoc typedefs in generator-components#1770

Closed
Kartikayy007 wants to merge 5 commits intoasyncapi:masterfrom
Kartikayy007:refactor/dedupe-jsdoc-components
Closed

refactor: deduplicate JSDoc typedefs in generator-components#1770
Kartikayy007 wants to merge 5 commits intoasyncapi:masterfrom
Kartikayy007:refactor/dedupe-jsdoc-components

Conversation

@Kartikayy007
Copy link
Contributor

@Kartikayy007 Kartikayy007 commented Nov 25, 2025

Description

This PR eliminates JSDoc typedef duplication by centralizing all type definitions in a shared types.js file.

Previously, the same typedefs (Language, SupportedLanguage, Format, QueryParamCodeBlock) were duplicated across 15 component files, causing maintenance overhead and risk of type drift.

Changes:

  • Created packages/components/src/types.js as single source of truth for all shared typedefs
  • Updated 15 component files to use @typedef {import('../types').TypeName} syntax instead of inline definitions
  • Exported types from index.js for package-level access
  • Added changeset

Testing:

  • All 81 tests pass
  • Lint passes with 0 warnings
  • Build successful
Screenshot 2025-11-25 at 7 44 56 PM

Related issue(s)

Fixes #1724

Summary by CodeRabbit

  • Refactor
    • Centralized Language, SupportedLanguage, ModelLanguage, Format and QueryParamCodeBlock type definitions into a shared types module.
    • Updated components to reference the centralized types instead of duplicating inline typedefs.
    • Re-exported the centralized types from the package entry for public availability.
    • Harmonized language variants (added 'js' alias) and unified query-param code-block shape.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

🦋 Changeset detected

Latest commit: 7f78ff9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/generator-components Patch

Not sure what this means? Click here to learn what changesets are.

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

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2025

Walkthrough

Centralizes duplicated JSDoc typedefs by adding packages/components/src/types.js, re-exports it from packages/components/src/index.js, and updates multiple component files to import Language, SupportedLanguage, Format, and QueryParamCodeBlock instead of declaring them inline. No runtime logic changes.

Changes

Cohort / File(s) Summary
Changelog documentation
\.changeset/dedupe-jsdoc-typedefs.md
Adds a changeset documenting the deduplication of JSDoc typedefs into a centralized types module.
Centralized types module
packages/components/src/types.js
New file introducing JSDoc typedefs: Language, SupportedLanguage, ModelLanguage, Format, and QueryParamCodeBlock (with nested properties).
Package exports
packages/components/src/index.js
Adds export * from './types.js' to re-export the centralized typedefs from the package entrypoint.
Components — Language typedefs replaced
packages/components/src/components/*CloseConnection.js, *DependencyProvider.js, *FileHeaderInfo.js, *HandleMessage.js, *MethodGenerator.js, *Models.js, *RegisterErrorHandler.js, *RegisterMessageHandler.js
Replace inline Language JSDoc unions with @typedef {import('../types').Language}.
Components — SupportedLanguage typedefs replaced
packages/components/src/components/Connect.js, OnClose.js, OnError.js, OnMessage.js, OnOpen.js, SendOperations.js, QueryParamsVariables.js
Replace inline SupportedLanguage JSDoc unions with @typedef {import('../types').SupportedLanguage}.
Components — Format typedef replaced
packages/components/src/components/Models.js
Replace inline Format JSDoc union with @typedef {import('../types').Format}.
Components — QueryParamCodeBlock typedef replaced
packages/components/src/components/QueryParamsVariables.js
Replace inline QueryParamCodeBlock object typedef with @typedef {import('../types').QueryParamCodeBlock}.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Repetitive changes limited to JSDoc typedef centralization and a single new types file.
  • Review attention:
    • Confirm packages/components/src/types.js enumerations match all previous literal variants used by components.
    • Verify relative import paths (import('../types')) in updated files.
    • Check QueryParamCodeBlock.closing optional/null annotation aligns with call sites.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: deduplicating JSDoc typedefs across components by centralizing them into a shared types.js file.
Linked Issues check ✅ Passed The PR successfully addresses the primary objective of #1724 by identifying and centralizing duplicated JSDoc typedefs (Language, SupportedLanguage, Format, QueryParamCodeBlock) across 15 component files into a shared types.js module.
Out of Scope Changes check ✅ Passed All changes are directly within scope: JSDoc typedef deduplication, creation of centralized types.js, updating imports across components, and exporting types. No unrelated refactoring or TypeScript migration is introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7768ec3 and 090d20f.

📒 Files selected for processing (2)
  • packages/components/src/components/Models.js (1 hunks)
  • packages/components/src/types.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/src/types.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • 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
  • GitHub Check: Test NodeJS PR - ubuntu-latest
  • GitHub Check: Test NodeJS PR - windows-latest
  • GitHub Check: Test NodeJS PR - macos-latest
🔇 Additional comments (1)
packages/components/src/components/Models.js (1)

12-15: Centralizing Format typedef via shared types.js looks correct

Importing Format from ../types keeps the string-union in one place and still matches the formatHelpers keys used below, so this aligns well with the PR’s DRY goal with no runtime impact.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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)
packages/components/src/components/CloseConnection.js (1)

3-6: Central Language typedef import is correct; note existing config shape mismatch

Switching to @typedef {import('../types').Language} is aligned with the shared types.js module and matches the languages used in websocketCloseConfig. One minor, pre‑existing nit: the JSDoc on websocketCloseConfig (Record<Language, { methodDocs?: string, methodLogic: string }> on Line 17) doesn’t quite describe the nested java: { quarkus: { ... } } shape. Not blocking here, but worth aligning when you revisit typings or move this to TypeScript.

packages/components/src/types.js (2)

1-24: Centralized typedefs align well with the refactor goals

The shared Language, SupportedLanguage, Format, and QueryParamCodeBlock typedefs look consistent and remove the prior duplication across components. Keeping SupportedLanguage as an alias for backward compatibility is a good touch.

If you want to push this a bit further, you could optionally introduce a small helper typedef for the repeated { text: string, indent?: number, newLines?: number } shape used by all QueryParamCodeBlock fields, but that’s purely a readability/DRY improvement and not required for this PR.


26-26: Address Sonar warning on export {} in a typedef‑only module

Sonar is flagging the bare export {}; as “export statement without specifiers is not allowed”. Since this file only contains JSDoc typedefs and has no runtime exports, you can safely drop that line and rely on the re‑export from index.js (or imports of this file) to treat it as a module where needed.

Suggestion: remove the empty export line to keep Sonar happy without changing behavior.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0dc9f60 and 9e214e9.

📒 Files selected for processing (18)
  • .changeset/dedupe-jsdoc-typedefs.md (1 hunks)
  • packages/components/src/components/CloseConnection.js (1 hunks)
  • packages/components/src/components/Connect.js (1 hunks)
  • packages/components/src/components/DependencyProvider.js (1 hunks)
  • packages/components/src/components/FileHeaderInfo.js (1 hunks)
  • packages/components/src/components/HandleMessage.js (1 hunks)
  • packages/components/src/components/MethodGenerator.js (1 hunks)
  • packages/components/src/components/Models.js (1 hunks)
  • packages/components/src/components/OnClose.js (1 hunks)
  • packages/components/src/components/OnError.js (1 hunks)
  • packages/components/src/components/OnMessage.js (1 hunks)
  • packages/components/src/components/OnOpen.js (1 hunks)
  • packages/components/src/components/QueryParamsVariables.js (1 hunks)
  • packages/components/src/components/RegisterErrorHandler.js (1 hunks)
  • packages/components/src/components/RegisterMessageHandler.js (1 hunks)
  • packages/components/src/components/SendOperations.js (1 hunks)
  • packages/components/src/index.js (1 hunks)
  • packages/components/src/types.js (1 hunks)
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
packages/components/src/types.js

[warning] 26-26: export statement without specifiers is not allowed.

See more on https://sonarcloud.io/project/issues?id=asyncapi_generator&issues=AZq7YTlJloyzcSe9_Zdv&open=AZq7YTlJloyzcSe9_Zdv&pullRequest=1770

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • 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
  • GitHub Check: Test NodeJS PR - windows-latest
  • GitHub Check: Test NodeJS PR - ubuntu-latest
  • GitHub Check: Test NodeJS PR - macos-latest
🔇 Additional comments (15)
packages/components/src/components/QueryParamsVariables.js (1)

5-11: Centralizing typedefs for query param generation looks good

Using @typedef {import('../types').SupportedLanguage} and QueryParamCodeBlock here is consistent with the new shared types.js module and removes local duplication without touching runtime behavior.

.changeset/dedupe-jsdoc-typedefs.md (1)

1-5: Changeset description matches the implemented refactor

The changeset clearly documents the JSDoc typedef deduplication into types.js and correctly uses a patch release for this non‑runtime change.

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

4-7: Shared Language typedef import is consistent with usage

Switching Language to @typedef {import('../types').Language} keeps this file aligned with the centralized type definition and matches the languages used in dependenciesConfig (python, javascript, dart, java).

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

15-17: Re-exporting types.js through the index is appropriate

Adding export * from './types.js'; cleanly surfaces the shared typedefs at the package level while preserving existing named exports. This is a safe, backward‑compatible enhancement.

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

4-7: Shared SupportedLanguage typedef import fits the send-operations config

Using @typedef {import('../types').SupportedLanguage} here removes the local union and keeps the language prop aligned with the centralized type used across components.

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

3-6: Typedef import for Language is correctly centralized

Referencing Language via import('../types').Language removes local duplication and stays consistent with the keys used in websocketErrorRegisterConfig.

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

3-6: Shared Language typedef is good; ensure it covers all header languages

Importing Language from ../types is consistent with the PR’s deduplication. Given commentConfig supports python, javascript, typescript, java, csharp, rust, and dart, just confirm the Language typedef in types.js includes this full set so the JSDoc stays accurate for tooling and any future TypeScript migration.

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

3-6: Centralized typedef usage looks correct

Using @typedef {import('../types').SupportedLanguage} here matches the new shared types module and keeps the prop / map typings consistent. No further changes needed in this file.

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

3-6: Language typedef import aligns with shared types

The switch to @typedef {import('../types').Language} cleanly centralizes the language union while keeping existing Record<Language, …> annotations intact. Looks good.

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

3-6: Shared Language typedef applied consistently

Referencing Language from ../types here keeps the message‑handler config in sync with the centralized language definition. No issues from this refactor.

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

3-6: HandleMessage now correctly reuses the shared Language typedef

The new @typedef {import('../types').Language} centralizes the language union without affecting runtime logic. All usages in this file remain type‑compatible.

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

3-6: OnMessage typedef now correctly references centralized SupportedLanguage

The change to @typedef {import('../types').SupportedLanguage} matches the shared types module and keeps the handler map and prop typings aligned. Looks good.

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

3-6: Shared SupportedLanguage typedef correctly adopted

Importing SupportedLanguage from ../types here aligns the OnClose typings with the centralized definitions and other components. No further adjustments needed.

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

7-10: Connect component now correctly reuses centralized SupportedLanguage

The typedef @typedef {import('../types').SupportedLanguage} cleanly replaces the inline union and keeps the language‑indexed config and props documentation in sync with the shared type.

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

3-6: OnError typedef centralization is consistent with the rest of the handlers

Using @typedef {import('../types').SupportedLanguage} here aligns this file with the shared types and other handler components, with no impact on runtime behavior.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a33a807 and 7768ec3.

📒 Files selected for processing (1)
  • packages/components/src/components/Models.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Acceptance tests for generated templates
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test NodeJS PR - macos-latest
  • GitHub Check: Test NodeJS PR - windows-latest
  • GitHub Check: Test NodeJS PR - ubuntu-latest

@sonarqubecloud
Copy link

@Kartikayy007 Kartikayy007 deleted the refactor/dedupe-jsdoc-components branch November 27, 2025 21:16
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.

Discuss duplication of JSDocs across components & potential migration to TypeScript of @asyncapi/generator-components

2 participants