asyncapi / parser-js

AsyncAPI parser for Javascript (browser-compatible too).
Apache License 2.0
120 stars 96 forks source link

[BUG] `operationMessagesUnambiguity` rule throws error if operation or message is not a `$ref`. #1037

Open kamil1094 opened 4 months ago

kamil1094 commented 4 months ago

Describe the bug.

I'm getting error like this:

cause: TypeError: Cannot read properties of undefined (reading 'startsWith')
        at /Users/kamil/workdir/tempBundler/node_modules/@asyncapi/parser/cjs/ruleset/v3/functions/operationMessagesUnambiguity.js:31:27
        at Array.forEach (<anonymous>)
        at /Users/kamil/workdir/tempBundler/node_modules/@asyncapi/parser/cjs/ruleset/v3/functions/operationMessagesUnambiguity.js:30:71
        at Object.function (/Users/kamil/workdir/tempBundler/node_modules/@stoplight/spectral-core/dist/ruleset/function.js:83:16)
        at lintNode (/Users/kamil/workdir/tempBundler/node_modules/@stoplight/spectral-core/dist/runner/lintNode.js:29:46)
        at cb (/Users/kamil/workdir/tempBundler/node_modules/@stoplight/spectral-core/dist/runner/runner.js:43:45)
        at mapped.<computed> (/Users/kamil/workdir/tempBundler/node_modules/@stoplight/spectral-core/dist/runner/runner.js:85:17)
        at _callbacks.<computed> (/Users/kamil/workdir/tempBundler/node_modules/nimma/dist/legacy/cjs/runtime/proxy-callbacks.js:31:9)
        at Scope.emit (/Users/kamil/workdir/tempBundler/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:109:19)
        at $.operations.* (eval at query (/Users/kamil/workdir/tempBundler/node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:21:11)

after using .validate() method on AsyncAPI document that contains operations with channel and messages components specified like the one below(without using $ref)

sendBranchCreatedToAnalyticsExchange:
    action: send
    channel:
      address: analytics
      messages:
        branchCreatedMessage:
          title: Branch created message
          summary: Event fired after a branch is created.
          payload:
            title: Branch created payload
              - type: object
                properties:
                  type:
                    type: string
                    const: something.branch.created
                    example: something.branch.created
                required:
                  - type
      bindings:
        amqp:
          is: routingKey
          exchange:
            name: analytics
            type: topic
            durable: true
            autoDelete: false
            vhost: /
          bindingVersion: 0.3.0
    messages:
      - title: Branch created message
        summary: Event fired after a branch is created.
        payload:
          title: Branch created payload
          allOf:
            - title: Base API event message
              type: object
              properties:
                id:
                  type: string
                  description: Event ID.
                  pattern: '^evt_[0-9abcdefghjkmnpqrstvwxyz]{26}$'
                  example: evt_01h1s5z6vf2mm1mz3hevnn9va7
              required:
                - id
    bindings:
      amqp:
        cc:
          - branch.created
        ack: false
        bindingVersion: 0.3.0

Expected behavior

I can validate document containing operations like the one specified above without getting errors.

Screenshots

-

How to Reproduce

  1. Create AsyncAPI document with operation specified above
  2. Try to validate document using @asyncapi/parser .validate method

🥦 Browser

None

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

github-actions[bot] commented 4 months 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.

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart: