Skip to content

fix: remove duplicate AsyncAPI spec loading in fromTemplate command (fixes #2017)#2157

Open
gavin913427-hash wants to merge 2 commits intoasyncapi:masterfrom
gavin913427-hash:fix/duplicate-spec-loading-v2
Open

fix: remove duplicate AsyncAPI spec loading in fromTemplate command (fixes #2017)#2157
gavin913427-hash wants to merge 2 commits intoasyncapi:masterfrom
gavin913427-hash:fix/duplicate-spec-loading-v2

Conversation

@gavin913427-hash
Copy link
Copy Markdown

What

Remove duplicate AsyncAPI specification loading in the fromTemplate command.

Why

The fromTemplate command was loading the AsyncAPI file twice during execution:

  1. Via this.loadAsyncAPIInput(asyncapi) on line 60
  2. Via load(asyncapi) on line 70

This caused:

  • Duplicate disk I/O
  • Duplicate parsing
  • Unnecessary memory usage
  • Slower execution for large specifications

How

  • Reuse the result from loadAsyncAPIInput() instead of calling load() again
  • Remove unused imports (load, ValidationError)
  • The loadAsyncAPIInput() method already handles error cases internally

Changes

File Change
src/apps/cli/commands/generate/fromTemplate.ts Reuse asyncapiInput for specification, remove duplicate load() call and unused imports

Testing

The command should work exactly as before, but faster for large spec files:

# Before: loads file twice
asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template -o ./docs

# After: loads file once
asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template -o ./docs

Fixes #2017

The fromTemplate command was loading the AsyncAPI file twice:
1. Via this.loadAsyncAPIInput(asyncapi) on line 60
2. Via load(asyncapi) on line 70

This caused duplicate disk I/O, parsing, and unnecessary memory usage.

Fix: Reuse the result from loadAsyncAPIInput() instead of loading again.

Fixes asyncapi#2017
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 3, 2026

🦋 Changeset detected

Latest commit: a6f6b61

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

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli 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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 3, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Duplicate AsyncAPI specification loading in fromTemplate.ts command (unnecessary double parsing)

1 participant