Skip to content

fix: remove duplicate AsyncAPI specification loading in fromTemplate command#2071

Closed
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/remove-duplicate-spec-loading-2017
Closed

fix: remove duplicate AsyncAPI specification loading in fromTemplate command#2071
chengyixu wants to merge 2 commits intoasyncapi:masterfrom
chengyixu:fix/remove-duplicate-spec-loading-2017

Conversation

@chengyixu
Copy link

Closes #2017

Problem

The generate fromTemplate command was loading the AsyncAPI specification file twice per invocation:

  1. loadAsyncAPIInput(asyncapi) — to populate this.specFile for metrics/watch mode
  2. load(asyncapi) — called immediately after to get a specification variable for generation

The result of the first load (asyncapiInput) was never reused for generation, so the second call was entirely redundant.

Fix

  • Moved the loadAsyncAPIInput() call inside the existing try/catch block so invalid-file errors are still handled with the correct ValidationError (same behaviour as before)
  • The single loaded specification is now assigned to both this.specFile and passed to generatorService.generate() — one disk read / YAML parse instead of two
  • Removed the now-unused load and Specification named imports from the file

Impact

  • No behaviour change — the Specification object returned by loadAsyncAPIInput() is the same as the one previously returned by the redundant load() call
  • Performance improvement — eliminates one full file read + YAML/JSON parse per generate fromTemplate run; most noticeable for large AsyncAPI documents

chengyixu and others added 2 commits March 22, 2026 01:53
…capi#1995)

- Update git-workflow.md link in DEVELOPMENT.md to correct path in
  asyncapi/community repo (moved from root to docs/010-contribution-guidelines/)
- Remove outdated asyncapi.x86.exe link from Windows installation section
  as 32-bit executable is no longer included in releases

Fixes asyncapi#1995
…command

Closes asyncapi#2017

The `fromTemplate` command was loading the AsyncAPI specification twice:

1. `loadAsyncAPIInput(asyncapi)` — called to populate `this.specFile`
   for metrics/watch mode tracking (stored in `asyncapiInput`)
2. `load(asyncapi)` — called again immediately to get the `specification`
   variable passed to `generatorService.generate()`

The result of the first load was assigned to `this.specFile` but never
reused for generation, making the second `load()` call redundant.

## Changes

- Wrap `loadAsyncAPIInput()` in the existing try/catch block so errors
  are handled with the proper `ValidationError` (identical to before)
- Assign the single load result to `this.specFile` and reuse it as the
  `specification` argument to `generatorService.generate()`
- Remove the now-unused `load` and `Specification` imports from the file

This eliminates one full disk read + YAML parse per `generate fromTemplate`
invocation, which is most noticeable for large specification files.
@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: 98b31bb

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

@github-project-automation github-project-automation bot moved this from To Triage to Done in CLI - Kanban Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants