fix: filter out $ref keys in bindings() to prevent undefined parser output#1173
fix: filter out $ref keys in bindings() to prevent undefined parser output#1173q404365631 wants to merge 2 commits into
Conversation
…r output Part of fix for asyncapi#877
…r output Part of fix for asyncapi#877
|
There was a problem hiding this comment.
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.
|
|
Hi! 👋 This PR fixes the issue where |



Description
Fixes #877
When AsyncAPI documents contain message bindings with
$refreferences (e.g.,{"$ref": "#/components/messageBindings/myBindings"}), the parser returnsundefinedinstead of properly parsing the document.Root Cause
The
bindings()function in bothv2/mixins.tsandv3/mixins.tsiterates over all entries of the bindings object usingObject.entries(), including$refkeys. When a$refkey is present, it gets treated as a protocol name (likekafka,amqp, etc.), causing theBindingmodel to be created with invalid data, which ultimately causes the parser to crash or returnundefined.Fix
Filter out keys starting with
$(such as$ref) before processing binding entries, consistent with how theextensions()function filters keys usingEXTENSION_REGEX.Changes
packages/parser/src/models/v3/mixins.ts: Added.filter(([key]) => !key.startsWith('$'))before.map()in thebindings()functionpackages/parser/src/models/v2/mixins.ts: Same fix applied to the v2bindings()functionTesting
The fix ensures that:
$refin bindings are parsed correctly instead of returningundefined$refreference data is preserved inoriginalDatafor downstream processingReproduction
Before fix:
Parser returns
undefinedfor this message.After fix:
Parser correctly creates the message model, with protocol bindings properly extracted (excluding the
$refkey).MICROGRANT
This PR resolves issue #877 which is part of the MICROGRANT Program 2026-06.