Skip to content

fix: filter out $ref keys in bindings() to prevent undefined parser output#1173

Closed
q404365631 wants to merge 3 commits into
asyncapi:masterfrom
q404365631:fix/bindings-ref-key-filter
Closed

fix: filter out $ref keys in bindings() to prevent undefined parser output#1173
q404365631 wants to merge 3 commits into
asyncapi:masterfrom
q404365631:fix/bindings-ref-key-filter

Conversation

@q404365631

Copy link
Copy Markdown

Description

Fixes #877

When AsyncAPI documents contain message bindings with $ref references (e.g., {"$ref": "#/components/messageBindings/myBindings"}), the parser returns undefined instead of properly parsing the document.

Root Cause

The bindings() function in both v2/mixins.ts and v3/mixins.ts iterates over all entries of the bindings object using Object.entries(), including $ref keys. When a $ref key is present, it gets treated as a protocol name (like kafka, amqp, etc.), causing the Binding model to be created with invalid data, which ultimately causes the parser to crash or return undefined.

Fix

Filter out keys starting with $ (such as $ref) before processing binding entries, consistent with how the extensions() function filters keys using EXTENSION_REGEX.

Changes

  • packages/parser/src/models/v3/mixins.ts: Added .filter(([key]) => !key.startsWith('$')) before .map() in the bindings() function
  • packages/parser/src/models/v2/mixins.ts: Same fix applied to the v2 bindings() function

Testing

The fix ensures that:

  1. Messages with $ref in bindings are parsed correctly instead of returning undefined
  2. Normal protocol bindings (kafka, amqp, http, etc.) continue to work as expected
  3. The $ref reference data is preserved in originalData for downstream processing

Reproduction

Before fix:

messages:
  myMessage:
    bindings:
      $ref: '#/components/messageBindings/myBindings'
    payload:
      type: object

Parser returns undefined for this message.

After fix:
Parser correctly creates the message model, with protocol bindings properly extracted (excluding the $ref key).

MICROGRANT

This PR resolves issue #877 which is part of the MICROGRANT Program 2026-06.

@changeset-bot

changeset-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 12f3e8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/parser Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@q404365631

Copy link
Copy Markdown
Author

Hi! 👋 This PR fixes the issue where $ref keys in bindings cause the parser to return undefined. The fix filters out $ref keys before processing. Could someone please take a look? Thanks!

@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

@princerajpoot20

Copy link
Copy Markdown
Member

the underline issue is part of microgrant program. please read the program guidlines https://github.com/asyncapi/community/blob/master/docs/010-contribution-guidelines/microgrant-program.md. thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser returns undefined when there's bindings in message

2 participants