Skip to content

[BUG] CLI fails with misleading error when AsyncAPI YAML contains multiple documents #1997

@sahillllllllll-bit

Description

@sahillllllllll-bit

Describe the bug.

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

While AsyncAPI itself supports only a single document, multi-document YAML is valid YAML and commonly appears in real-world workflows. The CLI should therefore fail explicitly and clearly, rather than falling into an incorrect parsing code path.


Why multiple YAML documents appear in practice

Multi-document YAML is widely used and often introduced unintentionally:

  • Common in Kubernetes and DevOps configurations
  • Users may merge or concatenate YAML files
  • Tooling or generators may emit multiple documents by default
  • Copy–paste workflows may leave --- separators behind
  • Users may comment out one document but leave the separator

Even if AsyncAPI does not support multi-document files, users reasonably expect the CLI to detect and clearly reject this case.

Expected behavior

When an AsyncAPI file contains multiple YAML documents, the CLI should:

  • Detect that multiple YAML documents are present
  • Fail early during validation
  • Return a clear, user-facing error explaining that only a single AsyncAPI document is supported

Example expected output:

Error: AsyncAPI files with multiple YAML documents are not supported.

Screenshots

Image

How to Reproduce

  1. Create an AsyncAPI file containing multiple YAML documents:
asyncapi: '2.6.0'
info:
  title: Test API
  version: '1.0.0'
channels: {}

---
asyncapi: '2.6.0'
info:
  title: Second Doc
  version: '1.0.0'
channels: {}
  1. Run the AsyncAPI CLI:
asyncapi generate fromTemplate asyncapi.yaml ./test-template --no-interactive
  1. Observe the CLI output.

🖥️ Device Information [optional]

  • Operating System (OS):Windows(WSL)
  • Browser:
  • Browser Version:

👀 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