-
-
Notifications
You must be signed in to change notification settings - Fork 318
Open
Labels
bugSomething isn't workingSomething isn't working
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!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
To Triage