-
-
Notifications
You must be signed in to change notification settings - Fork 437
Expand file tree
/
Copy pathenums.py
More file actions
296 lines (208 loc) · 7.34 KB
/
enums.py
File metadata and controls
296 lines (208 loc) · 7.34 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
"""Enum definitions for datamodel-code-generator.
This module contains all enum types used by the CLI and code generation,
separated from the main module to allow fast CLI startup without loading pydantic.
"""
from __future__ import annotations
from enum import Enum
from typing import Final
from typing_extensions import TypedDict
class DataclassArguments(TypedDict, total=False):
"""Arguments for @dataclass decorator."""
init: bool
repr: bool
eq: bool
order: bool
unsafe_hash: bool
frozen: bool
match_args: bool
kw_only: bool
slots: bool
weakref_slot: bool
MIN_VERSION: Final[int] = 10
MAX_VERSION: Final[int] = 13
DEFAULT_SHARED_MODULE_NAME: Final[str] = "shared"
class InputFileType(Enum):
"""Supported input file types for schema parsing."""
Auto = "auto"
OpenAPI = "openapi"
JsonSchema = "jsonschema"
Json = "json"
Yaml = "yaml"
Dict = "dict"
CSV = "csv"
GraphQL = "graphql"
class DataModelType(Enum):
"""Supported output data model types."""
PydanticBaseModel = "pydantic.BaseModel"
PydanticV2BaseModel = "pydantic_v2.BaseModel"
PydanticV2Dataclass = "pydantic_v2.dataclass"
DataclassesDataclass = "dataclasses.dataclass"
TypingTypedDict = "typing.TypedDict"
MsgspecStruct = "msgspec.Struct"
class ReuseScope(Enum):
"""Scope for model reuse deduplication.
module: Deduplicate identical models within each module (default).
tree: Deduplicate identical models across all modules, placing shared models in shared.py.
"""
Module = "module"
Tree = "tree"
class OpenAPIScope(Enum):
"""Scopes for OpenAPI model generation."""
Schemas = "schemas"
Paths = "paths"
Tags = "tags"
Parameters = "parameters"
Webhooks = "webhooks"
RequestBodies = "requestbodies"
class AllExportsScope(Enum):
"""Scope for __all__ exports in __init__.py.
children: Export models from direct child modules only.
recursive: Export models from all descendant modules recursively.
"""
Children = "children"
Recursive = "recursive"
class AllExportsCollisionStrategy(Enum):
"""Strategy for handling name collisions in recursive exports.
error: Raise an error when name collision is detected.
minimal_prefix: Add module prefix only to colliding names.
full_prefix: Add full module path prefix to all colliding names.
"""
Error = "error"
MinimalPrefix = "minimal-prefix"
FullPrefix = "full-prefix"
class FieldTypeCollisionStrategy(Enum):
"""Strategy for handling field name and type name collisions.
rename_field: Rename the field with a suffix and add alias (default).
rename_type: Rename the type class with a suffix to preserve field name.
"""
RenameField = "rename-field"
RenameType = "rename-type"
class NamingStrategy(Enum):
"""Strategy for generating unique model names when duplicates occur.
numbered: Append numeric suffix (Address1, Address2) [default].
parent_prefixed: Prefix with parent model name (CustomerAddress, UserAddress).
full_path: Use full schema path for unique names (OrdersItemsAddress).
primary_first: Prioritize primary schema definitions, others get suffix.
"""
Numbered = "numbered"
ParentPrefixed = "parent-prefixed"
FullPath = "full-path"
PrimaryFirst = "primary-first"
class ClassNameAffixScope(Enum):
"""Scope for applying class name prefix/suffix.
All: Apply to all classes including enums (default).
Models: Apply only to model classes (BaseModel, TypedDict, dataclass, msgspec).
Enums: Apply only to enum classes.
"""
All = "all"
Models = "models"
Enums = "enums"
class CollapseRootModelsNameStrategy(Enum):
"""Strategy for naming when collapsing root models with object references.
child: Keep the inner (child) model's name, remove the wrapper.
parent: Rename inner model to wrapper's name, remove the wrapper.
"""
Child = "child"
Parent = "parent"
class AllOfMergeMode(Enum):
"""Mode for field merging in allOf schemas.
constraints: Merge only constraint fields (minItems, maxItems, pattern, etc.) from parent.
all: Merge constraints plus annotation fields (default, examples) from parent.
none: Do not merge any fields from parent properties.
"""
Constraints = "constraints"
All = "all"
NoMerge = "none"
class AllOfClassHierarchy(Enum):
"""How to map allOf references to class hierarchies."""
IfNoConflict = "if-no-conflict"
Always = "always"
class GraphQLScope(Enum):
"""Scopes for GraphQL model generation."""
Schema = "schema"
class ReadOnlyWriteOnlyModelType(Enum):
"""Model generation strategy for readOnly/writeOnly fields.
RequestResponse: Generate only Request/Response model variants (no base model).
All: Generate Base, Request, and Response models.
"""
RequestResponse = "request-response"
All = "all"
class ModuleSplitMode(Enum):
"""Mode for splitting generated models into separate files.
Single: Generate one file per model class.
"""
Single = "single"
class TargetPydanticVersion(Enum):
"""Target Pydantic version for generated code.
V2: Generate code compatible with Pydantic 2.0+ (uses populate_by_name).
V2_11: Generate code for Pydantic 2.11+ (uses validate_by_name).
"""
V2 = "2"
V2_11 = "2.11"
class UnionMode(Enum):
"""Union discriminator mode for Pydantic v2."""
smart = "smart"
left_to_right = "left_to_right"
class InputModelRefStrategy(Enum):
"""Strategy for handling referenced types in --input-model.
RegenerateAll: Regenerate all referenced types into target output type.
ReuseForeign: Reuse types from different model families via import,
regenerate same-family types into target output type.
ReuseAll: Reuse all referenced types via import, no regeneration.
"""
RegenerateAll = "regenerate-all"
ReuseForeign = "reuse-foreign"
ReuseAll = "reuse-all"
class StrictTypes(Enum):
"""Strict type options for generated models."""
str = "str"
bytes = "bytes"
int = "int"
float = "float"
bool = "bool"
class JsonSchemaVersion(Enum):
"""JSON Schema draft versions.
Used to specify which JSON Schema draft to use for parsing and validation.
Different drafts have different features and semantics.
"""
Auto = "auto"
Draft04 = "draft-04"
Draft07 = "draft-07"
Draft201909 = "2019-09"
Draft202012 = "2020-12"
class OpenAPIVersion(Enum):
"""OpenAPI specification versions.
Used to specify which OpenAPI version to use for parsing.
Different versions have different schema semantics (e.g., nullable handling).
"""
Auto = "auto"
V20 = "2.0"
V30 = "3.0"
V31 = "3.1"
__all__ = [
"DEFAULT_SHARED_MODULE_NAME",
"MAX_VERSION",
"MIN_VERSION",
"AllExportsCollisionStrategy",
"AllExportsScope",
"AllOfClassHierarchy",
"AllOfMergeMode",
"ClassNameAffixScope",
"CollapseRootModelsNameStrategy",
"DataModelType",
"DataclassArguments",
"FieldTypeCollisionStrategy",
"GraphQLScope",
"InputFileType",
"InputModelRefStrategy",
"JsonSchemaVersion",
"ModuleSplitMode",
"NamingStrategy",
"OpenAPIScope",
"OpenAPIVersion",
"ReadOnlyWriteOnlyModelType",
"ReuseScope",
"StrictTypes",
"TargetPydanticVersion",
"UnionMode",
]