Coverage for faststream / specification / asyncapi / v3_0_0 / schema / operations.py: 88%
22 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-08 01:48 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-08 01:48 +0000
1from enum import Enum
2from typing import Any
4from pydantic import BaseModel, Field
5from typing_extensions import Self
7from faststream._internal._compat import PYDANTIC_V2
8from faststream.specification.schema.operation import Operation as OperationSpec
10from .bindings import OperationBinding
11from .channels import Channel
12from .tag import Tag
13from .utils import Reference
16class Action(str, Enum):
17 SEND = "send"
18 RECEIVE = "receive"
21class Operation(BaseModel):
22 """A class to represent an operation.
24 Attributes:
25 operation_id : ID of the operation
26 summary : summary of the operation
27 description : description of the operation
28 bindings : bindings of the operation
29 message : message of the operation
30 security : security details of the operation
31 tags : tags associated with the operation
32 """
34 action: Action
35 channel: Channel | Reference
37 summary: str | None = None
38 description: str | None = None
40 bindings: OperationBinding | None = None
42 messages: list[Reference] = Field(default_factory=list)
44 security: dict[str, list[str]] | None = None
46 # TODO
47 # traits
49 tags: list[Tag | dict[str, Any]] | None = None
51 if PYDANTIC_V2: 51 ↛ 56line 51 didn't jump to line 56 because the condition on line 51 was always true
52 model_config = {"extra": "allow"}
54 else:
56 class Config:
57 extra = "allow"
59 @classmethod
60 def from_sub(
61 cls,
62 messages: list[Reference],
63 channel: Reference,
64 operation: OperationSpec,
65 ) -> Self:
66 return cls(
67 action=Action.RECEIVE,
68 messages=messages,
69 channel=channel,
70 bindings=OperationBinding.from_sub(operation.bindings),
71 summary=None,
72 description=None,
73 security=None,
74 tags=None,
75 )
77 @classmethod
78 def from_pub(
79 cls,
80 messages: list[Reference],
81 channel: Reference,
82 operation: OperationSpec,
83 ) -> Self:
84 return cls(
85 action=Action.SEND,
86 messages=messages,
87 channel=channel,
88 bindings=OperationBinding.from_pub(operation.bindings),
89 summary=None,
90 description=None,
91 security=None,
92 tags=None,
93 )