operation-channel-in-channels

Since 0.12.0 · In the rulesets: Recommended at error, Strict at error, All at error

This rule checks that the channel of an operation under the root operations is a reference to a channel under the root channels.

Rule details

An operation names the channel it sends to or receives from with a reference. The specification requires the operations under the root operations to point at a channel under the root channels, and at no other place, so that every channel the application uses is listed there. A reference to components/channels, or to another file, is reported. A root entry that is a reference to an operation under components/operations is checked as that operation, once however many entries name it; an operation under components/operations that no root entry names may refer to any channel. A root entry that refers to another file is not checked.

The rule reports Operation channel '<ref>' must be a reference to a channel of the root channels ('#/channels/...') on the operation’s channel.

The rule is the counterpart of the AsyncAPI parser’s asyncapi3-required-operation-channel-unambiguity, which accepts a reference to another file’s channels and skips root entries that are references.

Turn the rule off for a spec that keeps its channels in another file: the linter does not read other files, and asyncapi validate accepts the reference.

Examples

Good.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
channels:
  petAdopted:
    address: pets.adopted
operations:
  onPetAdopted:
    action: receive
    channel:
      $ref: '#/channels/petAdopted'

Bad. The operation’s channel is under components.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
operations:
  onPetAdopted:
    action: receive
    channel:
      $ref: '#/components/channels/petAdopted'
components:
  channels:
    petAdopted:
      address: pets.adopted

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.asyncapi has the details.

commands:
  lint:
    asyncapi:
      rules:
        operation-channel-in-channels: off

Related rules

Further reading

Was this helpful?