[BUG] : AsyncAPI document is double-stringified in generated ZIP output
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- cli
Research direction
Start in src/domains/services/archiver.service.ts at appendAsyncAPIDocument, then reproduce the issue with test-archiver.ts using npx ts-node test-archiver.ts. Done means the generated ZIP's asyncapi.yml preserves the supplied YAML document as valid YAML rather than a quoted, escaped string.
Written by the indexing model from the issue text.
Description
Describe the bug.
In src/domains/services/archiver.service.ts, the method appendAsyncAPIDocument always applies:
asyncapi = JSON.stringify(asyncapi);
even when asyncapi is already a YAML or JSON string.
Because of this:
- The original document is converted into a JSON string literal.
- Newlines are escaped (\n) and the entire content is wrapped in quotes.
- The archived asyncapi.yml therefore contains a serialized string instead of a valid AsyncAPI document.
Expected behavior
For the test file mentioned in How to Reproduce section
The file should contain valid YAML:
asyncapi: 2.6.0
info:
title: Example
version: 1.0.0
Proposed fix
We can update the method to stringify only when the input is an object:
public appendAsyncAPIDocument(
archive: Archiver,
asyncapi: string | object,
fileName = 'asyncapi',
) {
const content =
typeof asyncapi === 'string'
? asyncapi
: JSON.stringify(asyncapi, null, 2);
const language = retrieveLangauge(content);
const extension = language === 'yaml' ? 'yml' : 'json';
archive.append(content, { name: `${fileName}.${extension}` });
}
Screenshots
How to Reproduce
- Create a test file named test-archiver.ts. Inside the test, pass an AsyncAPI document as a string:
import * as fs from 'fs';
import archiver from 'archiver';
import { ArchiverService } from './src/domains/services/archiver.service';
async function run() {
const output = fs.createWriteStream('test.zip');
const archive = archiver('zip');
archive.pipe(output);
const service = new ArchiverService();
const asyncapiString =
"asyncapi: 2.6.0\ninfo:\n title: Example\n version: 1.0.0";
service.appendAsyncAPIDocument(archive, asyncapiString);
await archive.finalize();
console.log('ZIP created');
}
run();
- Run the test script from the project root:
npx ts-node test-archiver.ts
- Allow the archiver service to generate the ZIP archive.
- Open the generated ZIP file.
- Open
asyncapi.ymlinside the archive.
🖥️ Device Information [optional]
- Operating System (OS): Windows 10
- Generator version : 3.0.1
👀 Have you checked for similar open issues?
- I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to work on this issue ?
Yes I am willing to submit a PR!
- Dominant language
- TypeScript
- Stars
- 274
- Forks
- 376
- Avg merge
- 12h 11m
- Merged PRs (30d)
- 11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from asyncapi/cli
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug stale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug stale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
🐞 docs bug stale
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug stale
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100