Skip to content

[BUG] : AsyncAPI document is double-stringified in generated ZIP output #2026

@Ishita-190

Description

@Ishita-190

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

Image

How to Reproduce

  1. 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();
  1. Run the test script from the project root:
npx ts-node test-archiver.ts
  1. Allow the archiver service to generate the ZIP archive.
  2. Open the generated ZIP file.
  3. Open asyncapi.yml inside 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?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions