Skip to content

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

Open

Description

@sahillllllllll-bit

Describe the bug.

File: src/apps/cli/commands/generate/fromTemplate.ts
The fromTemplate command loads the AsyncAPI file twice during execution.

First via:

const asyncapiInput = await this.loadAsyncAPIInput(asyncapi);

Then again via:

specification = await load(asyncapi);

This results in:

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

The first loaded result is not reused, making the second load redundant.

This is a performance inefficiency in CLI command flow.

Expected behavior

The AsyncAPI file should be loaded and parsed only once during command execution.

  • The result of loadAsyncAPIInput(asyncapi) should be reused for generation.
  • The CLI should not call load(asyncapi) again.
  • There should be no duplicate disk reads or parsing steps.
  • Large AsyncAPI files should not incur unnecessary performance overhead.
  • Command execution should remain functionally identical but more efficient.

Screenshots

Image

How to Reproduce

  1. Create a large AsyncAPI file (e.g., with many channels and components).

2.Run:

time asyncapi generate fromTemplate large.yaml @asyncapi/html-template -o out

  1. Observe execution time.

  2. Add logging inside:

load(asyncapi)

You will see it is invoked after loadAsyncAPIInput() already processed the file.

🖥️ Device Information [optional]

  • Operating System (OS): Windows(WSL)
  • Browser:
  • Browser Version:

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Activity

  1. sahillllllllll-bit commented on Feb 13, 2026

    @sahillllllllll-bit
    ContributorAuthor

    @Shurtu-gal @AayushSaini101 @Souvikns Waiting for approval :)

    Proposed Fix :

    Remove the redundant load(asyncapi) call and reuse the result from loadAsyncAPIInput(asyncapi).

    Replace this block:

    const asyncapiInput = await this.loadAsyncAPIInput(asyncapi);
    
    this.specFile = asyncapiInput;
    this.metricsMetadata.template = template;
    
    let specification: Specification;
    try {
      specification = await load(asyncapi);
    } catch {
      return this.error(
        new ValidationError({
          type: 'invalid-file',
          filepath: asyncapi,
        }),
        { exit: 1 },
      );
    }

    With this:

    let specification: Specification;
    try {
      specification = await this.loadAsyncAPIInput(asyncapi);
    } catch {
      return this.error(
        new ValidationError({
          type: 'invalid-file',
          filepath: asyncapi,
        }),
        { exit: 1 },
      );
    }
    
    this.specFile = specification;
    this.metricsMetadata.template = template;

    This ensures:

    • The AsyncAPI file is loaded only once
    • No duplicate disk I/O
    • No duplicate parsing
    • Improved performance for large specifications

    No change in functional behavior

  2. added a commit that references this issue on Mar 21, 2026
    98b31bb
  3. 1164148-7-eng commented on Mar 28, 2026

    @1164148-7-eng

    /attempt #2017

    I've claimed this issue. Working on it now! 🚀

  4. added a commit that references this issue on Mar 28, 2026
    f4b9989
  5. 1164148-7-eng commented on Mar 31, 2026

    @1164148-7-eng

    /attempt #2017

    I've claimed this issue. Working on it now! 🚀

  6. github-actions commented on Jul 29, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions