-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
124 lines (89 loc) · 2.21 KB
/
Copy pathmodel.py
File metadata and controls
124 lines (89 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from __future__ import annotations
from dataclasses import dataclass, field
from typing import TypeAlias
@dataclass(frozen=True)
class AnyAnnotation:
pass
@dataclass(frozen=True)
class DictAnnotation:
key: TypeAnnotation
value: TypeAnnotation
@dataclass(frozen=True)
class ListAnnotation:
item: TypeAnnotation
@dataclass(frozen=True)
class MappingAnnotation:
key: TypeAnnotation
value: TypeAnnotation
@dataclass(frozen=True)
class LiteralAnnotation:
values: tuple[object, ...]
@dataclass(frozen=True)
class NamedAnnotation:
name: str
@dataclass(frozen=True)
class TupleAnnotation:
items: tuple[TypeAnnotation, ...]
@dataclass(frozen=True)
class UnionAnnotation:
items: tuple[TypeAnnotation, ...]
TypeAnnotation: TypeAlias = (
AnyAnnotation
| DictAnnotation
| ListAnnotation
| MappingAnnotation
| LiteralAnnotation
| NamedAnnotation
| TupleAnnotation
| UnionAnnotation
)
@dataclass(frozen=True)
class FieldDef:
name: str
annotation: TypeAnnotation
required: bool
description: str | None = None
@dataclass(frozen=True)
class TypedDictDef:
name: str
fields: tuple[FieldDef, ...]
description: str | None = None
@dataclass(frozen=True)
class TypeAliasDef:
name: str
annotation: TypeAnnotation
@dataclass(frozen=True)
class EnumDef:
name: str
values: tuple[object, ...]
@dataclass(frozen=True)
class OperationDef:
method: str
route_literal: str
symbol: str
protocol_name: str
params_type: TypeAnnotation
params_required: bool
query_type: TypeAnnotation
query_required: bool
headers_type: TypeAnnotation
headers_required: bool
body_type: TypeAnnotation | None
body_required: bool
response_type: TypeAnnotation
@dataclass(frozen=True)
class NormalizedSpec:
package_name: str
typed_dicts: tuple[TypedDictDef, ...]
aliases: tuple[TypeAliasDef, ...]
enums: tuple[EnumDef, ...]
operations: tuple[OperationDef, ...]
@dataclass(frozen=True)
class GeneratedArtifact:
relative_path: str
content: str
@dataclass
class RenderContext:
package_name: str
import_typing: set[str] = field(default_factory=set)
import_typeddict: bool = False