datamodel-code-generator 0.27.2__py3-none-any.whl → 0.28.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datamodel-code-generator might be problematic. Click here for more details.
- datamodel_code_generator/__init__.py +168 -196
- datamodel_code_generator/__main__.py +146 -189
- datamodel_code_generator/arguments.py +227 -230
- datamodel_code_generator/format.py +77 -129
- datamodel_code_generator/http.py +12 -10
- datamodel_code_generator/imports.py +59 -65
- datamodel_code_generator/model/__init__.py +28 -31
- datamodel_code_generator/model/base.py +100 -144
- datamodel_code_generator/model/dataclass.py +62 -70
- datamodel_code_generator/model/enum.py +34 -30
- datamodel_code_generator/model/imports.py +13 -11
- datamodel_code_generator/model/msgspec.py +116 -138
- datamodel_code_generator/model/pydantic/__init__.py +18 -28
- datamodel_code_generator/model/pydantic/base_model.py +121 -140
- datamodel_code_generator/model/pydantic/custom_root_type.py +2 -2
- datamodel_code_generator/model/pydantic/dataclass.py +6 -4
- datamodel_code_generator/model/pydantic/imports.py +35 -33
- datamodel_code_generator/model/pydantic/types.py +91 -119
- datamodel_code_generator/model/pydantic_v2/__init__.py +21 -18
- datamodel_code_generator/model/pydantic_v2/base_model.py +118 -127
- datamodel_code_generator/model/pydantic_v2/imports.py +5 -3
- datamodel_code_generator/model/pydantic_v2/root_model.py +6 -6
- datamodel_code_generator/model/pydantic_v2/types.py +11 -7
- datamodel_code_generator/model/rootmodel.py +1 -1
- datamodel_code_generator/model/scalar.py +33 -32
- datamodel_code_generator/model/typed_dict.py +41 -51
- datamodel_code_generator/model/types.py +24 -19
- datamodel_code_generator/model/union.py +21 -17
- datamodel_code_generator/parser/__init__.py +16 -12
- datamodel_code_generator/parser/base.py +327 -515
- datamodel_code_generator/parser/graphql.py +87 -119
- datamodel_code_generator/parser/jsonschema.py +438 -607
- datamodel_code_generator/parser/openapi.py +180 -220
- datamodel_code_generator/pydantic_patch.py +8 -9
- datamodel_code_generator/reference.py +199 -297
- datamodel_code_generator/types.py +149 -215
- datamodel_code_generator/util.py +23 -36
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.28.0.dist-info}/METADATA +10 -5
- datamodel_code_generator-0.28.0.dist-info/RECORD +59 -0
- datamodel_code_generator-0.27.2.dist-info/RECORD +0 -59
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.28.0.dist-info}/WHEEL +0 -0
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.28.0.dist-info}/entry_points.txt +0 -0
- {datamodel_code_generator-0.27.2.dist-info → datamodel_code_generator-0.28.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from decimal import Decimal
|
|
4
|
-
from typing import Any, ClassVar
|
|
4
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
5
5
|
|
|
6
|
-
from datamodel_code_generator.format import DatetimeClassType, PythonVersion
|
|
6
|
+
from datamodel_code_generator.format import DatetimeClassType, PythonVersion, PythonVersionMin
|
|
7
7
|
from datamodel_code_generator.imports import (
|
|
8
8
|
IMPORT_ANY,
|
|
9
9
|
IMPORT_DATE,
|
|
@@ -53,17 +53,20 @@ from datamodel_code_generator.model.pydantic.imports import (
|
|
|
53
53
|
from datamodel_code_generator.types import DataType, StrictTypes, Types, UnionIntFloat
|
|
54
54
|
from datamodel_code_generator.types import DataTypeManager as _DataTypeManager
|
|
55
55
|
|
|
56
|
+
if TYPE_CHECKING:
|
|
57
|
+
from collections.abc import Sequence
|
|
58
|
+
|
|
56
59
|
|
|
57
60
|
def type_map_factory(
|
|
58
|
-
data_type:
|
|
61
|
+
data_type: type[DataType],
|
|
59
62
|
strict_types: Sequence[StrictTypes],
|
|
60
63
|
pattern_key: str,
|
|
61
|
-
use_pendulum: bool,
|
|
62
|
-
target_datetime_class: DatetimeClassType,
|
|
63
|
-
) ->
|
|
64
|
-
data_type_int = data_type(type=
|
|
65
|
-
data_type_float = data_type(type=
|
|
66
|
-
data_type_str = data_type(type=
|
|
64
|
+
use_pendulum: bool, # noqa: FBT001
|
|
65
|
+
target_datetime_class: DatetimeClassType, # noqa: ARG001
|
|
66
|
+
) -> dict[Types, DataType]:
|
|
67
|
+
data_type_int = data_type(type="int")
|
|
68
|
+
data_type_float = data_type(type="float")
|
|
69
|
+
data_type_str = data_type(type="str")
|
|
67
70
|
result = {
|
|
68
71
|
Types.integer: data_type_int,
|
|
69
72
|
Types.int32: data_type_int,
|
|
@@ -75,7 +78,7 @@ def type_map_factory(
|
|
|
75
78
|
Types.time: data_type.from_import(IMPORT_TIME),
|
|
76
79
|
Types.string: data_type_str,
|
|
77
80
|
Types.byte: data_type_str, # base64 encoded string
|
|
78
|
-
Types.binary: data_type(type=
|
|
81
|
+
Types.binary: data_type(type="bytes"),
|
|
79
82
|
Types.date: data_type.from_import(IMPORT_DATE),
|
|
80
83
|
Types.date_time: data_type.from_import(IMPORT_DATETIME),
|
|
81
84
|
Types.timedelta: data_type.from_import(IMPORT_TIMEDELTA),
|
|
@@ -94,17 +97,18 @@ def type_map_factory(
|
|
|
94
97
|
strict=StrictTypes.str in strict_types,
|
|
95
98
|
# https://github.com/horejsek/python-fastjsonschema/blob/61c6997a8348b8df9b22e029ca2ba35ef441fbb8/fastjsonschema/draft04.py#L31
|
|
96
99
|
kwargs={
|
|
97
|
-
pattern_key: r"r'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\.)*
|
|
98
|
-
|
|
100
|
+
pattern_key: r"r'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\.)*"
|
|
101
|
+
r"([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9])\Z'",
|
|
102
|
+
**({"strict": True} if StrictTypes.str in strict_types else {}),
|
|
99
103
|
},
|
|
100
104
|
),
|
|
101
105
|
Types.ipv4: data_type.from_import(IMPORT_IPV4ADDRESS),
|
|
102
106
|
Types.ipv6: data_type.from_import(IMPORT_IPV6ADDRESS),
|
|
103
107
|
Types.ipv4_network: data_type.from_import(IMPORT_IPV4NETWORKS),
|
|
104
108
|
Types.ipv6_network: data_type.from_import(IMPORT_IPV6NETWORKS),
|
|
105
|
-
Types.boolean: data_type(type=
|
|
109
|
+
Types.boolean: data_type(type="bool"),
|
|
106
110
|
Types.object: data_type.from_import(IMPORT_ANY, is_dict=True),
|
|
107
|
-
Types.null: data_type(type=
|
|
111
|
+
Types.null: data_type(type="None"),
|
|
108
112
|
Types.array: data_type.from_import(IMPORT_ANY, is_list=True),
|
|
109
113
|
Types.any: data_type.from_import(IMPORT_ANY),
|
|
110
114
|
}
|
|
@@ -117,7 +121,7 @@ def type_map_factory(
|
|
|
117
121
|
return result
|
|
118
122
|
|
|
119
123
|
|
|
120
|
-
def strict_type_map_factory(data_type:
|
|
124
|
+
def strict_type_map_factory(data_type: type[DataType]) -> dict[StrictTypes, DataType]:
|
|
121
125
|
return {
|
|
122
126
|
StrictTypes.int: data_type.from_import(IMPORT_STRICT_INT, strict=True),
|
|
123
127
|
StrictTypes.float: data_type.from_import(IMPORT_STRICT_FLOAT, strict=True),
|
|
@@ -127,44 +131,42 @@ def strict_type_map_factory(data_type: Type[DataType]) -> Dict[StrictTypes, Data
|
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
|
|
130
|
-
number_kwargs:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
number_kwargs: set[str] = {
|
|
135
|
+
"exclusiveMinimum",
|
|
136
|
+
"minimum",
|
|
137
|
+
"exclusiveMaximum",
|
|
138
|
+
"maximum",
|
|
139
|
+
"multipleOf",
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
string_kwargs:
|
|
142
|
+
string_kwargs: set[str] = {"minItems", "maxItems", "minLength", "maxLength", "pattern"}
|
|
139
143
|
|
|
140
|
-
byes_kwargs:
|
|
144
|
+
byes_kwargs: set[str] = {"minLength", "maxLength"}
|
|
141
145
|
|
|
142
|
-
escape_characters = str.maketrans(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
)
|
|
146
|
+
escape_characters = str.maketrans({
|
|
147
|
+
"'": r"\'",
|
|
148
|
+
"\b": r"\b",
|
|
149
|
+
"\f": r"\f",
|
|
150
|
+
"\n": r"\n",
|
|
151
|
+
"\r": r"\r",
|
|
152
|
+
"\t": r"\t",
|
|
153
|
+
})
|
|
152
154
|
|
|
153
155
|
|
|
154
156
|
class DataTypeManager(_DataTypeManager):
|
|
155
|
-
PATTERN_KEY: ClassVar[str] =
|
|
157
|
+
PATTERN_KEY: ClassVar[str] = "regex"
|
|
156
158
|
|
|
157
|
-
def __init__(
|
|
159
|
+
def __init__( # noqa: PLR0913, PLR0917
|
|
158
160
|
self,
|
|
159
|
-
python_version: PythonVersion =
|
|
160
|
-
use_standard_collections: bool = False,
|
|
161
|
-
use_generic_container_types: bool = False,
|
|
162
|
-
strict_types:
|
|
163
|
-
use_non_positive_negative_number_constrained_types: bool = False,
|
|
164
|
-
use_union_operator: bool = False,
|
|
165
|
-
use_pendulum: bool = False,
|
|
166
|
-
target_datetime_class:
|
|
167
|
-
):
|
|
161
|
+
python_version: PythonVersion = PythonVersionMin,
|
|
162
|
+
use_standard_collections: bool = False, # noqa: FBT001, FBT002
|
|
163
|
+
use_generic_container_types: bool = False, # noqa: FBT001, FBT002
|
|
164
|
+
strict_types: Sequence[StrictTypes] | None = None,
|
|
165
|
+
use_non_positive_negative_number_constrained_types: bool = False, # noqa: FBT001, FBT002
|
|
166
|
+
use_union_operator: bool = False, # noqa: FBT001, FBT002
|
|
167
|
+
use_pendulum: bool = False, # noqa: FBT001, FBT002
|
|
168
|
+
target_datetime_class: DatetimeClassType | None = None,
|
|
169
|
+
) -> None:
|
|
168
170
|
super().__init__(
|
|
169
171
|
python_version,
|
|
170
172
|
use_standard_collections,
|
|
@@ -176,36 +178,36 @@ class DataTypeManager(_DataTypeManager):
|
|
|
176
178
|
target_datetime_class,
|
|
177
179
|
)
|
|
178
180
|
|
|
179
|
-
self.type_map:
|
|
181
|
+
self.type_map: dict[Types, DataType] = self.type_map_factory(
|
|
180
182
|
self.data_type,
|
|
181
183
|
strict_types=self.strict_types,
|
|
182
184
|
pattern_key=self.PATTERN_KEY,
|
|
183
185
|
target_datetime_class=self.target_datetime_class,
|
|
184
186
|
)
|
|
185
|
-
self.strict_type_map:
|
|
187
|
+
self.strict_type_map: dict[StrictTypes, DataType] = strict_type_map_factory(
|
|
186
188
|
self.data_type,
|
|
187
189
|
)
|
|
188
190
|
|
|
189
|
-
self.kwargs_schema_to_model:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
self.kwargs_schema_to_model: dict[str, str] = {
|
|
192
|
+
"exclusiveMinimum": "gt",
|
|
193
|
+
"minimum": "ge",
|
|
194
|
+
"exclusiveMaximum": "lt",
|
|
195
|
+
"maximum": "le",
|
|
196
|
+
"multipleOf": "multiple_of",
|
|
197
|
+
"minItems": "min_items",
|
|
198
|
+
"maxItems": "max_items",
|
|
199
|
+
"minLength": "min_length",
|
|
200
|
+
"maxLength": "max_length",
|
|
201
|
+
"pattern": self.PATTERN_KEY,
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
def type_map_factory(
|
|
203
205
|
self,
|
|
204
|
-
data_type:
|
|
206
|
+
data_type: type[DataType],
|
|
205
207
|
strict_types: Sequence[StrictTypes],
|
|
206
208
|
pattern_key: str,
|
|
207
|
-
target_datetime_class: DatetimeClassType,
|
|
208
|
-
) ->
|
|
209
|
+
target_datetime_class: DatetimeClassType, # noqa: ARG002
|
|
210
|
+
) -> dict[Types, DataType]:
|
|
209
211
|
return type_map_factory(
|
|
210
212
|
data_type,
|
|
211
213
|
strict_types,
|
|
@@ -214,47 +216,35 @@ class DataTypeManager(_DataTypeManager):
|
|
|
214
216
|
self.target_datetime_class,
|
|
215
217
|
)
|
|
216
218
|
|
|
217
|
-
def transform_kwargs(
|
|
218
|
-
self,
|
|
219
|
-
) -> Dict[str, str]:
|
|
220
|
-
return {
|
|
221
|
-
self.kwargs_schema_to_model.get(k, k): v
|
|
222
|
-
for (k, v) in kwargs.items()
|
|
223
|
-
if v is not None and k in filter_
|
|
224
|
-
}
|
|
219
|
+
def transform_kwargs(self, kwargs: dict[str, Any], filter_: set[str]) -> dict[str, str]:
|
|
220
|
+
return {self.kwargs_schema_to_model.get(k, k): v for (k, v) in kwargs.items() if v is not None and k in filter_}
|
|
225
221
|
|
|
226
|
-
def get_data_int_type(
|
|
222
|
+
def get_data_int_type( # noqa: PLR0911
|
|
227
223
|
self,
|
|
228
224
|
types: Types,
|
|
229
225
|
**kwargs: Any,
|
|
230
226
|
) -> DataType:
|
|
231
|
-
data_type_kwargs:
|
|
227
|
+
data_type_kwargs: dict[str, Any] = self.transform_kwargs(kwargs, number_kwargs)
|
|
232
228
|
strict = StrictTypes.int in self.strict_types
|
|
233
229
|
if data_type_kwargs:
|
|
234
230
|
if not strict:
|
|
235
|
-
if data_type_kwargs == {
|
|
231
|
+
if data_type_kwargs == {"gt": 0}:
|
|
236
232
|
return self.data_type.from_import(IMPORT_POSITIVE_INT)
|
|
237
|
-
if data_type_kwargs == {
|
|
233
|
+
if data_type_kwargs == {"lt": 0}:
|
|
238
234
|
return self.data_type.from_import(IMPORT_NEGATIVE_INT)
|
|
239
|
-
if
|
|
240
|
-
data_type_kwargs == {'ge': 0}
|
|
241
|
-
and self.use_non_positive_negative_number_constrained_types
|
|
242
|
-
):
|
|
235
|
+
if data_type_kwargs == {"ge": 0} and self.use_non_positive_negative_number_constrained_types:
|
|
243
236
|
return self.data_type.from_import(IMPORT_NON_NEGATIVE_INT)
|
|
244
|
-
if
|
|
245
|
-
data_type_kwargs == {'le': 0}
|
|
246
|
-
and self.use_non_positive_negative_number_constrained_types
|
|
247
|
-
):
|
|
237
|
+
if data_type_kwargs == {"le": 0} and self.use_non_positive_negative_number_constrained_types:
|
|
248
238
|
return self.data_type.from_import(IMPORT_NON_POSITIVE_INT)
|
|
249
239
|
kwargs = {k: int(v) for k, v in data_type_kwargs.items()}
|
|
250
240
|
if strict:
|
|
251
|
-
kwargs[
|
|
241
|
+
kwargs["strict"] = True
|
|
252
242
|
return self.data_type.from_import(IMPORT_CONINT, kwargs=kwargs)
|
|
253
243
|
if strict:
|
|
254
244
|
return self.strict_type_map[StrictTypes.int]
|
|
255
245
|
return self.type_map[types]
|
|
256
246
|
|
|
257
|
-
def get_data_float_type(
|
|
247
|
+
def get_data_float_type( # noqa: PLR0911
|
|
258
248
|
self,
|
|
259
249
|
types: Types,
|
|
260
250
|
**kwargs: Any,
|
|
@@ -263,23 +253,17 @@ class DataTypeManager(_DataTypeManager):
|
|
|
263
253
|
strict = StrictTypes.float in self.strict_types
|
|
264
254
|
if data_type_kwargs:
|
|
265
255
|
if not strict:
|
|
266
|
-
if data_type_kwargs == {
|
|
256
|
+
if data_type_kwargs == {"gt": 0}:
|
|
267
257
|
return self.data_type.from_import(IMPORT_POSITIVE_FLOAT)
|
|
268
|
-
if data_type_kwargs == {
|
|
258
|
+
if data_type_kwargs == {"lt": 0}:
|
|
269
259
|
return self.data_type.from_import(IMPORT_NEGATIVE_FLOAT)
|
|
270
|
-
if
|
|
271
|
-
data_type_kwargs == {'ge': 0}
|
|
272
|
-
and self.use_non_positive_negative_number_constrained_types
|
|
273
|
-
):
|
|
260
|
+
if data_type_kwargs == {"ge": 0} and self.use_non_positive_negative_number_constrained_types:
|
|
274
261
|
return self.data_type.from_import(IMPORT_NON_NEGATIVE_FLOAT)
|
|
275
|
-
if
|
|
276
|
-
data_type_kwargs == {'le': 0}
|
|
277
|
-
and self.use_non_positive_negative_number_constrained_types
|
|
278
|
-
):
|
|
262
|
+
if data_type_kwargs == {"le": 0} and self.use_non_positive_negative_number_constrained_types:
|
|
279
263
|
return self.data_type.from_import(IMPORT_NON_POSITIVE_FLOAT)
|
|
280
264
|
kwargs = {k: float(v) for k, v in data_type_kwargs.items()}
|
|
281
265
|
if strict:
|
|
282
|
-
kwargs[
|
|
266
|
+
kwargs["strict"] = True
|
|
283
267
|
return self.data_type.from_import(IMPORT_CONFLOAT, kwargs=kwargs)
|
|
284
268
|
if strict:
|
|
285
269
|
return self.strict_type_map[StrictTypes.float]
|
|
@@ -290,23 +274,18 @@ class DataTypeManager(_DataTypeManager):
|
|
|
290
274
|
if data_type_kwargs:
|
|
291
275
|
return self.data_type.from_import(
|
|
292
276
|
IMPORT_CONDECIMAL,
|
|
293
|
-
kwargs={
|
|
294
|
-
k: Decimal(str(v) if isinstance(v, UnionIntFloat) else v)
|
|
295
|
-
for k, v in data_type_kwargs.items()
|
|
296
|
-
},
|
|
277
|
+
kwargs={k: Decimal(str(v) if isinstance(v, UnionIntFloat) else v) for k, v in data_type_kwargs.items()},
|
|
297
278
|
)
|
|
298
279
|
return self.type_map[types]
|
|
299
280
|
|
|
300
281
|
def get_data_str_type(self, types: Types, **kwargs: Any) -> DataType:
|
|
301
|
-
data_type_kwargs:
|
|
282
|
+
data_type_kwargs: dict[str, Any] = self.transform_kwargs(kwargs, string_kwargs)
|
|
302
283
|
strict = StrictTypes.str in self.strict_types
|
|
303
284
|
if data_type_kwargs:
|
|
304
285
|
if strict:
|
|
305
|
-
data_type_kwargs[
|
|
286
|
+
data_type_kwargs["strict"] = True
|
|
306
287
|
if self.PATTERN_KEY in data_type_kwargs:
|
|
307
|
-
escaped_regex = data_type_kwargs[self.PATTERN_KEY].translate(
|
|
308
|
-
escape_characters
|
|
309
|
-
)
|
|
288
|
+
escaped_regex = data_type_kwargs[self.PATTERN_KEY].translate(escape_characters)
|
|
310
289
|
# TODO: remove unneeded escaped characters
|
|
311
290
|
data_type_kwargs[self.PATTERN_KEY] = f"r'{escaped_regex}'"
|
|
312
291
|
return self.data_type.from_import(IMPORT_CONSTR, kwargs=data_type_kwargs)
|
|
@@ -315,39 +294,32 @@ class DataTypeManager(_DataTypeManager):
|
|
|
315
294
|
return self.type_map[types]
|
|
316
295
|
|
|
317
296
|
def get_data_bytes_type(self, types: Types, **kwargs: Any) -> DataType:
|
|
318
|
-
data_type_kwargs:
|
|
297
|
+
data_type_kwargs: dict[str, Any] = self.transform_kwargs(kwargs, byes_kwargs)
|
|
319
298
|
strict = StrictTypes.bytes in self.strict_types
|
|
320
|
-
if data_type_kwargs:
|
|
321
|
-
|
|
322
|
-
return self.data_type.from_import(
|
|
323
|
-
IMPORT_CONBYTES, kwargs=data_type_kwargs
|
|
324
|
-
)
|
|
299
|
+
if data_type_kwargs and not strict:
|
|
300
|
+
return self.data_type.from_import(IMPORT_CONBYTES, kwargs=data_type_kwargs)
|
|
325
301
|
# conbytes doesn't accept strict argument
|
|
326
302
|
# https://github.com/samuelcolvin/pydantic/issues/2489
|
|
327
|
-
# if strict:
|
|
328
|
-
# data_type_kwargs['strict'] = True
|
|
329
|
-
# return self.data_type.from_import(IMPORT_CONBYTES, kwargs=data_type_kwargs)
|
|
330
303
|
if strict:
|
|
331
304
|
return self.strict_type_map[StrictTypes.bytes]
|
|
332
305
|
return self.type_map[types]
|
|
333
306
|
|
|
334
|
-
def get_data_type(
|
|
307
|
+
def get_data_type( # noqa: PLR0911
|
|
335
308
|
self,
|
|
336
309
|
types: Types,
|
|
337
310
|
**kwargs: Any,
|
|
338
311
|
) -> DataType:
|
|
339
312
|
if types == Types.string:
|
|
340
313
|
return self.get_data_str_type(types, **kwargs)
|
|
341
|
-
|
|
314
|
+
if types in {Types.int32, Types.int64, Types.integer}:
|
|
342
315
|
return self.get_data_int_type(types, **kwargs)
|
|
343
|
-
|
|
316
|
+
if types in {Types.float, Types.double, Types.number, Types.time}:
|
|
344
317
|
return self.get_data_float_type(types, **kwargs)
|
|
345
|
-
|
|
318
|
+
if types == Types.decimal:
|
|
346
319
|
return self.get_data_decimal_type(types, **kwargs)
|
|
347
|
-
|
|
320
|
+
if types == Types.binary:
|
|
348
321
|
return self.get_data_bytes_type(types, **kwargs)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return self.strict_type_map[StrictTypes.bool]
|
|
322
|
+
if types == Types.boolean and StrictTypes.bool in self.strict_types:
|
|
323
|
+
return self.strict_type_map[StrictTypes.bool]
|
|
352
324
|
|
|
353
325
|
return self.type_map[types]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import TYPE_CHECKING, Optional
|
|
4
4
|
|
|
5
5
|
from pydantic import BaseModel as _BaseModel
|
|
6
6
|
|
|
@@ -8,29 +8,32 @@ from .base_model import BaseModel, DataModelField, UnionMode
|
|
|
8
8
|
from .root_model import RootModel
|
|
9
9
|
from .types import DataTypeManager
|
|
10
10
|
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from collections.abc import Iterable
|
|
13
|
+
|
|
11
14
|
|
|
12
15
|
def dump_resolve_reference_action(class_names: Iterable[str]) -> str:
|
|
13
|
-
return
|
|
16
|
+
return "\n".join(f"{class_name}.model_rebuild()" for class_name in class_names)
|
|
14
17
|
|
|
15
18
|
|
|
16
19
|
class ConfigDict(_BaseModel):
|
|
17
|
-
extra: Optional[str] = None
|
|
18
|
-
title: Optional[str] = None
|
|
19
|
-
populate_by_name: Optional[bool] = None
|
|
20
|
-
allow_extra_fields: Optional[bool] = None
|
|
21
|
-
from_attributes: Optional[bool] = None
|
|
22
|
-
frozen: Optional[bool] = None
|
|
23
|
-
arbitrary_types_allowed: Optional[bool] = None
|
|
24
|
-
protected_namespaces: Optional[
|
|
25
|
-
regex_engine: Optional[str] = None
|
|
26
|
-
use_enum_values: Optional[bool] = None
|
|
20
|
+
extra: Optional[str] = None # noqa: UP045
|
|
21
|
+
title: Optional[str] = None # noqa: UP045
|
|
22
|
+
populate_by_name: Optional[bool] = None # noqa: UP045
|
|
23
|
+
allow_extra_fields: Optional[bool] = None # noqa: UP045
|
|
24
|
+
from_attributes: Optional[bool] = None # noqa: UP045
|
|
25
|
+
frozen: Optional[bool] = None # noqa: UP045
|
|
26
|
+
arbitrary_types_allowed: Optional[bool] = None # noqa: UP045
|
|
27
|
+
protected_namespaces: Optional[tuple[str, ...]] = None # noqa: UP045
|
|
28
|
+
regex_engine: Optional[str] = None # noqa: UP045
|
|
29
|
+
use_enum_values: Optional[bool] = None # noqa: UP045
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
__all__ = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
"BaseModel",
|
|
34
|
+
"DataModelField",
|
|
35
|
+
"DataTypeManager",
|
|
36
|
+
"RootModel",
|
|
37
|
+
"UnionMode",
|
|
38
|
+
"dump_resolve_reference_action",
|
|
36
39
|
]
|