asyncapi / asyncapi/cli

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

Open
#2,017 4 comments 0 reactions 0 assignees View on GitHub
bug stale
Dominant language
TypeScript
Stars
272
Forks
375
Avg merge
3h 22m
Merged PRs (30d)
8

Description

### Describe the bug.

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

First via:

```ts
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

```
2. Observe execution time.

3. 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?

- [x] I checked and didn't find similar issue

### 🏢 Have you read the Contributing Guidelines?

- [x] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)

### Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.