Linter rulesAsyncAPIchannel-addresses-unique
channel-addresses-unique
Since 0.9.0
This rule checks that no two channels of an AsyncAPI document share the same address, including addresses that differ only by the names of their parameters.
Rule Details
In AsyncAPI 3.x the key of a channel in the channels map is only an
identifier; the actual topic, queue or routing key is given by the channel’s
address. Two channels with the same address describe the same destination,
which is usually a copy-and-paste mistake and makes it unclear which of the
two definitions (and which set of messages) is authoritative.
The channel-addresses-unique rule compares the addresses of all channels
defined in the root channels map. Before comparing, the name of every
parameter expression is dropped, so users.{userId}.events and
users.{id}.events are considered duplicates, as they match exactly the same
set of concrete addresses.
The rule reports Duplicate channel address found on every channel whose
address duplicates the address of a channel defined earlier in the document.
Channels without an address (or with address: null, meaning the address
is dynamic or unknown) are ignored. Channels defined under
components/channels are not checked.
Configuration
None.
Examples
Good. Each channel has its own address.
asyncapi: 3.0.0
info:
title: Pet Events
version: 1.0.0
channels:
petCreated:
address: pets.{petId}.created
parameters:
petId:
description: Identifier of the pet.
petDeleted:
address: pets.{petId}.deleted
parameters:
petId:
description: Identifier of the pet.
Bad. Both channels point to the same destination; they differ only by the parameter name.
asyncapi: 3.0.0
info:
title: Pet Events
version: 1.0.0
channels:
petEvents:
address: pets.{petId}.events
parameters:
petId:
description: Identifier of the pet.
animalEvents:
address: pets.{animalId}.events
parameters:
animalId:
description: Identifier of the animal.
When Not to Use It
You may disable this rule if you intentionally describe the same destination with several channels, for example when the channels are available on different servers and carry different messages.
Compatibility
This rule is compatible with AsyncAPI 3.x documents. AsyncAPI 2.x documents are rejected by the reader and are not linted.