Skip to content

fix: prevent double-stringification of AsyncAPI document in archiver (fixes #2026)#2166

Open
gavin913427-hash wants to merge 1 commit intoasyncapi:masterfrom
gavin913427-hash:fix/double-stringify-archiver
Open

fix: prevent double-stringification of AsyncAPI document in archiver (fixes #2026)#2166
gavin913427-hash wants to merge 1 commit intoasyncapi:masterfrom
gavin913427-hash:fix/double-stringify-archiver

Conversation

@gavin913427-hash
Copy link
Copy Markdown

What

Prevent double-stringification of AsyncAPI documents in the archiver service.

Why

The appendAsyncAPIDocument method was always applying JSON.stringify() even when the input was already a string. This caused:

  • YAML documents to be serialized as JSON string literals
  • Newlines to be escaped (\n)
  • The archived asyncapi.yml to contain a serialized string instead of a valid AsyncAPI document

How

  • Changed the method to only stringify when the input is an object
  • Updated the type signature to accept string | object
  • When input is a string, use it directly
  • When input is an object, stringify with pretty-printing (null, 2)

Changes

File Change
src/domains/services/archiver.service.ts Fix double-stringification, update type signature

Testing

# Before: archived file contains serialized string
asyncapi archive asyncapi.yaml
# asyncapi.yml contains: "\"asyncapi: 2.6.0\ninfo:\n  title: Example\n  version: 1.0.0\""

# After: archived file contains valid YAML
asyncapi archive asyncapi.yaml
# asyncapi.yml contains: asyncapi: 2.6.0\ninfo:\n  title: Example\n  version: 1.0.0

Fixes #2026

The appendAsyncAPIDocument method was always applying JSON.stringify()
even when the input was already a string. This caused:
- YAML documents to be serialized as JSON string literals
- Newlines to be escaped (\n)
- Invalid archived files

Now the method only stringifies when the input is an object.

Fixes asyncapi#2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

⚠️ No Changeset found

Latest commit: 8d3081c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

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

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

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

1 participant