Skip to content

fix: detect and reject multi-document YAML files with clear error (fixes #1997)#2115

Open
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:bounty/1997-multidoc-yaml
Open

fix: detect and reject multi-document YAML files with clear error (fixes #1997)#2115
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:bounty/1997-multidoc-yaml

Conversation

@armorbreak001
Copy link
Copy Markdown

Description

Fixes #1997

Problem

When an AsyncAPI YAML file contains multiple documents (separated by ---), the CLI fails with a confusing low-level parser error instead of clearly detecting the condition.

Multi-document YAML is valid YAML and commonly appears in real workflows (Kubernetes configs, merged files, copy-paste artifacts). Users reasonably expect a clear rejection message.

Solution

Detect multiple YAML document separators (---) in Specification.fromFile() before parsing. If more than one separator is found, throw a clear error:

Error: File contains multiple YAML documents (2 separators found).
AsyncAPI only supports single-document YAML files.
Please split the file or remove extra --- separators.

Changes

  • src/domains/models/SpecificationFile.ts: Multi-doc detection in fromFile()
  • src/errors/specification-file.ts: Extended ErrorLoadingSpec with optional customMessage param for specific error context

Testing

  • Only triggers on files with 2+ --- separators at start of line
  • Preserves normal single-document file loading behavior
  • Error message is actionable — tells user exactly what to do

 asyncapi#1997)

When a YAML file contains multiple documents separated by ---,
the parser produces confusing low-level errors. This fix detects
multi-document YAML early in Specification.fromFile() and throws
a clear, user-facing error message.

Also extends ErrorLoadingSpec to support optional customMessage
parameter for more specific error context.

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

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: 958c107

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

@github-project-automation github-project-automation bot moved this to To Triage in CLI - Kanban Apr 13, 2026
Extended multi-document YAML detection to fromURL() in addition
to fromFile(). URLs can also return multi-document YAML content.
@sonarqubecloud
Copy link
Copy Markdown

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] CLI fails with misleading error when AsyncAPI YAML contains multiple documents

1 participant