Coverage for faststream/confluent/subscriber/specification.py: 95%
20 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
1from faststream._internal.endpoint.subscriber import SubscriberSpecification
2from faststream.confluent.configs import KafkaBrokerConfig
3from faststream.specification.asyncapi.utils import resolve_payloads
4from faststream.specification.schema import Message, Operation, SubscriberSpec
5from faststream.specification.schema.bindings import ChannelBinding, kafka
7from .config import KafkaSubscriberSpecificationConfig
10class KafkaSubscriberSpecification(
11 SubscriberSpecification[KafkaBrokerConfig, KafkaSubscriberSpecificationConfig],
12):
13 __slots__ = ()
15 @property
16 def topics(self) -> list[str]:
17 """The topics this endpoint reads, in the order they were declared.
19 Deduped through a dict rather than a set: set order varies per process and
20 would reach the document as the order of its channels.
21 """
22 prefix = self._outer_config.prefix
24 topics = [f"{prefix}{t.name}" for t in self.config.topics]
25 topics.extend(f"{prefix}{p.topic}" for p in self.config.partitions)
27 return list(dict.fromkeys(topics))
29 @property
30 def channel_labels(self) -> list[str]:
31 return self.topics
33 def get_schema(self) -> dict[str, SubscriberSpec]:
34 payloads = self.get_payloads()
36 topics = self.topics
37 split = len(topics) > 1
39 channels = {}
40 for t in topics:
41 handler_name = self._channel_key(t, split=split)
43 channels[handler_name] = SubscriberSpec(
44 address=t,
45 description=self.description,
46 operation=Operation(
47 message=Message(
48 title=f"{handler_name}:Message",
49 payload=resolve_payloads(payloads),
50 ),
51 bindings=None,
52 ),
53 bindings=ChannelBinding(
54 kafka=kafka.ChannelBinding(
55 topic=t,
56 partitions=None,
57 replicas=None,
58 ),
59 ),
60 )
62 return channels