Coverage for faststream / specification / asyncapi / v2_6_0 / schema / servers.py: 77%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-08 01:48 +0000

1from typing import Any 

2 

3from pydantic import BaseModel 

4 

5from faststream._internal._compat import PYDANTIC_V2 

6from faststream.specification.asyncapi.v2_6_0.schema.tag import Tag 

7from faststream.specification.asyncapi.v2_6_0.schema.utils import Reference 

8 

9SecurityRequirement = list[dict[str, list[str]]] 

10 

11 

12class ServerVariable(BaseModel): 

13 """A class to represent a server variable. 

14 

15 Attributes: 

16 enum : list of possible values for the server variable (optional) 

17 default : default value for the server variable (optional) 

18 description : description of the server variable (optional) 

19 examples : list of example values for the server variable (optional) 

20 """ 

21 

22 enum: list[str] | None = None 

23 default: str | None = None 

24 description: str | None = None 

25 examples: list[str] | None = None 

26 

27 if PYDANTIC_V2: 27 ↛ 32line 27 didn't jump to line 32 because the condition on line 27 was always true

28 model_config = {"extra": "allow"} 

29 

30 else: 

31 

32 class Config: 

33 extra = "allow" 

34 

35 

36class Server(BaseModel): 

37 """A class to represent a server. 

38 

39 Attributes: 

40 url : URL of the server 

41 protocol : protocol used by the server 

42 description : optional description of the server 

43 protocolVersion : optional version of the protocol used by the server 

44 tags : optional list of tags associated with the server 

45 security : optional security requirement for the server 

46 variables : optional dictionary of server variables 

47 bindings : optional server binding 

48 

49 Note: 

50 The attributes `description`, `protocolVersion`, `tags`, `security`, `variables`, and `bindings` are all optional. 

51 """ 

52 

53 url: str 

54 protocol: str 

55 protocolVersion: str | None 

56 description: str | None = None 

57 tags: list[Tag | dict[str, Any]] | None = None 

58 security: SecurityRequirement | None = None 

59 

60 variables: dict[str, ServerVariable | Reference] | None = None 

61 

62 if PYDANTIC_V2: 62 ↛ 67line 62 didn't jump to line 67 because the condition on line 62 was always true

63 model_config = {"extra": "allow"} 

64 

65 else: 

66 

67 class Config: 

68 extra = "allow"