Skip to content

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

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

fix: filter out $ref keys in bindings() to prevent undefined parser output#1173
q404365631 wants to merge 2 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
Copy link
Copy Markdown

changeset-bot Bot commented Jun 1, 2026

⚠️ No Changeset found

Latest commit: 64fb034

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

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 1, 2026

@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!

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

1 participant