channel-addresses-unique
Since 0.9.0 · In the rulesets: Strict at error, All at error
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.
Turn the rule off if you intentionally describe the same destination with several channels, for example when the channels are available on different servers and carry different messages.
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.
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:
channel-addresses-unique: off