diff --git a/faststream/specification/asyncapi/v2_6_0/generate.py b/faststream/specification/asyncapi/v2_6_0/generate.py index 3882ae0a11..aa56d9582a 100644 --- a/faststream/specification/asyncapi/v2_6_0/generate.py +++ b/faststream/specification/asyncapi/v2_6_0/generate.py @@ -150,16 +150,25 @@ def get_broker_channels( channels = {} for h in broker._subscribers: - # TODO: add duplication key warning - channels.update({ - key: Channel.from_sub(channel) for key, channel in h.schema().items() - }) - + for key, channel in h.schema().items(): + if key in channels: + warnings.warn( + f"Overwrite channel handler, channels have the same names: `{key}`", + RuntimeWarning, + stacklevel=1, + ) + channels[key] = Channel.from_sub(channel) + for p in broker._publishers: - # TODO: add duplication key warning - channels.update({ - key: Channel.from_pub(channel) for key, channel in p.schema().items() - }) + for key, channel in p.schema().items(): + if key in channels: + warnings.warn( + f"Overwrite channel handler, channels have the same names: `{key}`", + RuntimeWarning, + stacklevel=1, + ) + + channels[key] = Channel.from_pub(channel) return channels diff --git a/faststream/specification/asyncapi/v3_0_0/generate.py b/faststream/specification/asyncapi/v3_0_0/generate.py index 3c4aec1051..0ef22bf909 100644 --- a/faststream/specification/asyncapi/v3_0_0/generate.py +++ b/faststream/specification/asyncapi/v3_0_0/generate.py @@ -158,7 +158,13 @@ def get_broker_channels( channel_obj = Channel.from_sub(sub_key, sub_channel) channel_key = clear_key(sub_key) - # TODO: add duplication key warning + if channel_key in channels: + warnings.warn( + f"Overwrite channel handler, channels have the same names: `{channel_key}`", + RuntimeWarning, + stacklevel=1, + ) + channels[channel_key] = channel_obj operations[f"{channel_key}Subscribe"] = Operation.from_sub( @@ -177,7 +183,12 @@ def get_broker_channels( channel_obj = Channel.from_pub(pub_key, pub_channel) channel_key = clear_key(pub_key) - # TODO: add duplication key warning + if channel_key in channels: + warnings.warn( + f"Overwrite channel handler, channels have the same names: `{channel_key}`", + RuntimeWarning, + stacklevel=1, + ) channels[channel_key] = channel_obj operations[channel_key] = Operation.from_pub(