asyncapi / parser-js

AsyncAPI parser for Javascript (browser-compatible too).
115 stars 91 forks source link

[BUG] Parsing yields error due to correlation between a Channel and Operation #996

Closed g-radam closed 1 month ago

g-radam commented 1 month ago

Describe the bug.

The parser yields an error due to some correlation between a Channel address being null and its associated Operation not having traits: [] defined. Either changing the address to be not-null, OR, adding a traits: [] field to the operation will suppress the error.

Note that Operation Traits are NOT required by the spec, so being forced to add a traits: [] field to an operation due to a channel address being null is quite erroneous. I have zero insight into where such an issue could be stemming from.

Expected behavior

Traits can be omitted from operations without an error, regardless of if the associated channel has a null address.

Screenshots

Studio link to the error

1:1 Error thrown during AsyncAPI document parsing.
Name: TypeError, message: Cannot read properties of null (reading 'traits'),
stack: TypeError: Cannot read properties of null (reading 'traits') at 
https://studio.asyncapi.com/static/js/main.827b380d.js:2:28752 at callback 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:28928) at _._handleCallback 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:3947909) at _._trace 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:3948061) at 
https://studio.asyncapi.com/static/js/main.827b380d.js:2:3948326 at 
https://studio.asyncapi.com/static/js/main.827b380d.js:2:3951499 at Array.forEach (<anonymous>) at _._walk 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:3951478) at _._trace 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:3948301) at _._trace 
(https://studio.asyncapi.com/static/js/main.827b380d.js:2:3948249)

How to Reproduce

Below is a minimal reproducible example:

asyncapi: 3.0.0
info:
  title: Acme Server API
  version: 1.0.0
channels:
  Exchange:
    address: nunotnullactually  <------------------- Make this null, and ensure there is NO `traits` on the operation, to cause the error
    messages:
      FooEvent:
        name: FooEvent
        title: Tenant Created
        contentType: application/json
        payload:
          type: string
operations:
  sendTenantCreated:
    title: Send tenant created event to client
    action: send
    #traits: []    <------------------------------------------ Adding this suppresses the error when address is null.
    channel:
      $ref: '#/channels/Exchange'
    messages:
      - $ref: '#/channels/Exchange/messages/FooEvent'

🥦 Browser

None

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it

github-actions[bot] commented 1 month ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup 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.