datamodel-code-generator 0.25.4__py3-none-any.whl → 0.25.6__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 +8 -3
- datamodel_code_generator/__main__.py +22 -2
- datamodel_code_generator/arguments.py +12 -0
- datamodel_code_generator/format.py +6 -9
- datamodel_code_generator/http.py +6 -1
- datamodel_code_generator/imports.py +4 -0
- datamodel_code_generator/model/base.py +1 -2
- datamodel_code_generator/model/msgspec.py +1 -0
- datamodel_code_generator/model/pydantic/types.py +16 -2
- datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2 +1 -1
- datamodel_code_generator/model/types.py +2 -0
- datamodel_code_generator/parser/base.py +45 -26
- datamodel_code_generator/parser/graphql.py +4 -0
- datamodel_code_generator/parser/jsonschema.py +8 -3
- datamodel_code_generator/parser/openapi.py +4 -0
- datamodel_code_generator/types.py +3 -0
- datamodel_code_generator/util.py +1 -2
- datamodel_code_generator/version.py +1 -1
- {datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/METADATA +7 -1
- {datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/RECORD +23 -23
- {datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/WHEEL +1 -1
- {datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/LICENSE +0 -0
- {datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/entry_points.txt +0 -0
|
@@ -58,8 +58,7 @@ def load_yaml_from_path(path: Path, encoding: str) -> Any:
|
|
|
58
58
|
|
|
59
59
|
if TYPE_CHECKING:
|
|
60
60
|
|
|
61
|
-
def get_version() -> str:
|
|
62
|
-
...
|
|
61
|
+
def get_version() -> str: ...
|
|
63
62
|
|
|
64
63
|
else:
|
|
65
64
|
|
|
@@ -300,6 +299,8 @@ def generate(
|
|
|
300
299
|
custom_file_header_path: Optional[Path] = None,
|
|
301
300
|
custom_formatters: Optional[List[str]] = None,
|
|
302
301
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
302
|
+
use_pendulum: bool = False,
|
|
303
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
303
304
|
) -> None:
|
|
304
305
|
remote_text_cache: DefaultPutDict[str, str] = DefaultPutDict()
|
|
305
306
|
if isinstance(input_, str):
|
|
@@ -309,7 +310,9 @@ def generate(
|
|
|
309
310
|
|
|
310
311
|
input_text = remote_text_cache.get_or_put(
|
|
311
312
|
input_.geturl(),
|
|
312
|
-
default_factory=lambda url: get_body(
|
|
313
|
+
default_factory=lambda url: get_body(
|
|
314
|
+
url, http_headers, http_ignore_tls, http_query_parameters
|
|
315
|
+
),
|
|
313
316
|
)
|
|
314
317
|
else:
|
|
315
318
|
input_text = None
|
|
@@ -456,6 +459,8 @@ def generate(
|
|
|
456
459
|
known_third_party=data_model_types.known_third_party,
|
|
457
460
|
custom_formatters=custom_formatters,
|
|
458
461
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
462
|
+
use_pendulum=use_pendulum,
|
|
463
|
+
http_query_parameters=http_query_parameters,
|
|
459
464
|
**kwargs,
|
|
460
465
|
)
|
|
461
466
|
|
|
@@ -94,8 +94,7 @@ class Config(BaseModel):
|
|
|
94
94
|
if TYPE_CHECKING:
|
|
95
95
|
|
|
96
96
|
@classmethod
|
|
97
|
-
def get_fields(cls) -> Dict[str, Any]:
|
|
98
|
-
...
|
|
97
|
+
def get_fields(cls) -> Dict[str, Any]: ...
|
|
99
98
|
|
|
100
99
|
else:
|
|
101
100
|
|
|
@@ -198,6 +197,23 @@ class Config(BaseModel):
|
|
|
198
197
|
return [validate_each_item(each_item) for each_item in value]
|
|
199
198
|
return value # pragma: no cover
|
|
200
199
|
|
|
200
|
+
@field_validator('http_query_parameters', mode='before')
|
|
201
|
+
def validate_http_query_parameters(
|
|
202
|
+
cls, value: Any
|
|
203
|
+
) -> Optional[List[Tuple[str, str]]]:
|
|
204
|
+
def validate_each_item(each_item: Any) -> Tuple[str, str]:
|
|
205
|
+
if isinstance(each_item, str): # pragma: no cover
|
|
206
|
+
try:
|
|
207
|
+
field_name, field_value = each_item.split('=', maxsplit=1) # type: str, str
|
|
208
|
+
return field_name, field_value.lstrip()
|
|
209
|
+
except ValueError:
|
|
210
|
+
raise Error(f'Invalid http query parameter: {each_item!r}')
|
|
211
|
+
return each_item # pragma: no cover
|
|
212
|
+
|
|
213
|
+
if isinstance(value, list):
|
|
214
|
+
return [validate_each_item(each_item) for each_item in value]
|
|
215
|
+
return value # pragma: no cover
|
|
216
|
+
|
|
201
217
|
@model_validator(mode='before')
|
|
202
218
|
def validate_additional_imports(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
|
203
219
|
if values.get('additional_imports') is not None:
|
|
@@ -294,6 +310,8 @@ class Config(BaseModel):
|
|
|
294
310
|
custom_file_header_path: Optional[Path] = None
|
|
295
311
|
custom_formatters: Optional[List[str]] = None
|
|
296
312
|
custom_formatters_kwargs: Optional[TextIOBase] = None
|
|
313
|
+
use_pendulum: bool = False
|
|
314
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None
|
|
297
315
|
|
|
298
316
|
def merge_args(self, args: Namespace) -> None:
|
|
299
317
|
set_args = {
|
|
@@ -488,6 +506,8 @@ def main(args: Optional[Sequence[str]] = None) -> Exit:
|
|
|
488
506
|
custom_file_header_path=config.custom_file_header_path,
|
|
489
507
|
custom_formatters=config.custom_formatters,
|
|
490
508
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
509
|
+
use_pendulum=config.use_pendulum,
|
|
510
|
+
http_query_parameters=config.http_query_parameters,
|
|
491
511
|
)
|
|
492
512
|
return Exit.OK
|
|
493
513
|
except InvalidClassNameError as e:
|
|
@@ -57,6 +57,12 @@ base_options.add_argument(
|
|
|
57
57
|
metavar='HTTP_HEADER',
|
|
58
58
|
help='Set headers in HTTP requests to the remote host. (example: "Authorization: Basic dXNlcjpwYXNz")',
|
|
59
59
|
)
|
|
60
|
+
base_options.add_argument(
|
|
61
|
+
'--http-query-parameters',
|
|
62
|
+
nargs='+',
|
|
63
|
+
metavar='HTTP_QUERY_PARAMETERS',
|
|
64
|
+
help='Set query parameters in HTTP requests to the remote host. (example: "ref=branch")',
|
|
65
|
+
)
|
|
60
66
|
base_options.add_argument(
|
|
61
67
|
'--http-ignore-tls',
|
|
62
68
|
help="Disable verification of the remote host's TLS certificate",
|
|
@@ -166,6 +172,12 @@ model_options.add_argument(
|
|
|
166
172
|
action='store_true',
|
|
167
173
|
default=None,
|
|
168
174
|
)
|
|
175
|
+
model_options.add_argument(
|
|
176
|
+
'--use-pendulum',
|
|
177
|
+
help='use pendulum instead of datetime',
|
|
178
|
+
action='store_true',
|
|
179
|
+
default=False,
|
|
180
|
+
)
|
|
169
181
|
|
|
170
182
|
# ======================================================================================
|
|
171
183
|
# Typing options for generated models
|
|
@@ -76,8 +76,7 @@ class PythonVersion(Enum):
|
|
|
76
76
|
|
|
77
77
|
if TYPE_CHECKING:
|
|
78
78
|
|
|
79
|
-
class _TargetVersion(Enum):
|
|
80
|
-
...
|
|
79
|
+
class _TargetVersion(Enum): ...
|
|
81
80
|
|
|
82
81
|
BLACK_PYTHON_VERSION: Dict[PythonVersion, _TargetVersion]
|
|
83
82
|
else:
|
|
@@ -98,8 +97,7 @@ def black_find_project_root(sources: Sequence[Path]) -> Path:
|
|
|
98
97
|
|
|
99
98
|
def _find_project_root(
|
|
100
99
|
srcs: Union[Sequence[str], Iterable[str]],
|
|
101
|
-
) -> Union[Tuple[Path, str], Path]:
|
|
102
|
-
...
|
|
100
|
+
) -> Union[Tuple[Path, str], Path]: ...
|
|
103
101
|
|
|
104
102
|
else:
|
|
105
103
|
from black import find_project_root as _find_project_root
|
|
@@ -153,9 +151,9 @@ class CodeFormatter:
|
|
|
153
151
|
f' for wrapping string literal in {black.__version__}'
|
|
154
152
|
)
|
|
155
153
|
elif black.__version__ < '24.1.0': # type: ignore
|
|
156
|
-
black_kwargs[
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
black_kwargs['experimental_string_processing'] = (
|
|
155
|
+
experimental_string_processing
|
|
156
|
+
)
|
|
159
157
|
elif experimental_string_processing:
|
|
160
158
|
black_kwargs['preview'] = True
|
|
161
159
|
black_kwargs['unstable'] = config.get('unstable', False)
|
|
@@ -240,8 +238,7 @@ class CodeFormatter:
|
|
|
240
238
|
|
|
241
239
|
if TYPE_CHECKING:
|
|
242
240
|
|
|
243
|
-
def apply_isort(self, code: str) -> str:
|
|
244
|
-
...
|
|
241
|
+
def apply_isort(self, code: str) -> str: ...
|
|
245
242
|
|
|
246
243
|
else:
|
|
247
244
|
if isort.__version__.startswith('4.'):
|
datamodel_code_generator/http.py
CHANGED
|
@@ -14,9 +14,14 @@ def get_body(
|
|
|
14
14
|
url: str,
|
|
15
15
|
headers: Optional[Sequence[Tuple[str, str]]] = None,
|
|
16
16
|
ignore_tls: bool = False,
|
|
17
|
+
query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
17
18
|
) -> str:
|
|
18
19
|
return httpx.get(
|
|
19
|
-
url,
|
|
20
|
+
url,
|
|
21
|
+
headers=headers,
|
|
22
|
+
verify=not ignore_tls,
|
|
23
|
+
follow_redirects=True,
|
|
24
|
+
params=query_parameters,
|
|
20
25
|
).text
|
|
21
26
|
|
|
22
27
|
|
|
@@ -116,5 +116,9 @@ IMPORT_DICT = Import.from_full_path('typing.Dict')
|
|
|
116
116
|
IMPORT_DECIMAL = Import.from_full_path('decimal.Decimal')
|
|
117
117
|
IMPORT_DATE = Import.from_full_path('datetime.date')
|
|
118
118
|
IMPORT_DATETIME = Import.from_full_path('datetime.datetime')
|
|
119
|
+
IMPORT_PATH = Import.from_full_path('pathlib.Path')
|
|
119
120
|
IMPORT_TIME = Import.from_full_path('datetime.time')
|
|
120
121
|
IMPORT_UUID = Import.from_full_path('uuid.UUID')
|
|
122
|
+
IMPORT_PENDULUM_DATE = Import.from_full_path('pendulum.Date')
|
|
123
|
+
IMPORT_PENDULUM_DATETIME = Import.from_full_path('pendulum.DateTime')
|
|
124
|
+
IMPORT_PENDULUM_TIME = Import.from_full_path('pendulum.Time')
|
|
@@ -9,6 +9,10 @@ from datamodel_code_generator.imports import (
|
|
|
9
9
|
IMPORT_DATE,
|
|
10
10
|
IMPORT_DATETIME,
|
|
11
11
|
IMPORT_DECIMAL,
|
|
12
|
+
IMPORT_PATH,
|
|
13
|
+
IMPORT_PENDULUM_DATE,
|
|
14
|
+
IMPORT_PENDULUM_DATETIME,
|
|
15
|
+
IMPORT_PENDULUM_TIME,
|
|
12
16
|
IMPORT_TIME,
|
|
13
17
|
IMPORT_UUID,
|
|
14
18
|
)
|
|
@@ -52,11 +56,12 @@ def type_map_factory(
|
|
|
52
56
|
data_type: Type[DataType],
|
|
53
57
|
strict_types: Sequence[StrictTypes],
|
|
54
58
|
pattern_key: str,
|
|
59
|
+
use_pendulum: bool,
|
|
55
60
|
) -> Dict[Types, DataType]:
|
|
56
61
|
data_type_int = data_type(type='int')
|
|
57
62
|
data_type_float = data_type(type='float')
|
|
58
63
|
data_type_str = data_type(type='str')
|
|
59
|
-
|
|
64
|
+
result = {
|
|
60
65
|
Types.integer: data_type_int,
|
|
61
66
|
Types.int32: data_type_int,
|
|
62
67
|
Types.int64: data_type_int,
|
|
@@ -70,6 +75,7 @@ def type_map_factory(
|
|
|
70
75
|
Types.binary: data_type(type='bytes'),
|
|
71
76
|
Types.date: data_type.from_import(IMPORT_DATE),
|
|
72
77
|
Types.date_time: data_type.from_import(IMPORT_DATETIME),
|
|
78
|
+
Types.path: data_type.from_import(IMPORT_PATH),
|
|
73
79
|
Types.password: data_type.from_import(IMPORT_SECRET_STR),
|
|
74
80
|
Types.email: data_type.from_import(IMPORT_EMAIL_STR),
|
|
75
81
|
Types.uuid: data_type.from_import(IMPORT_UUID),
|
|
@@ -98,6 +104,12 @@ def type_map_factory(
|
|
|
98
104
|
Types.array: data_type.from_import(IMPORT_ANY, is_list=True),
|
|
99
105
|
Types.any: data_type.from_import(IMPORT_ANY),
|
|
100
106
|
}
|
|
107
|
+
if use_pendulum:
|
|
108
|
+
result[Types.date] = data_type.from_import(IMPORT_PENDULUM_DATE)
|
|
109
|
+
result[Types.date_time] = data_type.from_import(IMPORT_PENDULUM_DATETIME)
|
|
110
|
+
result[Types.time] = data_type.from_import(IMPORT_PENDULUM_TIME)
|
|
111
|
+
|
|
112
|
+
return result
|
|
101
113
|
|
|
102
114
|
|
|
103
115
|
def strict_type_map_factory(data_type: Type[DataType]) -> Dict[StrictTypes, DataType]:
|
|
@@ -145,6 +157,7 @@ class DataTypeManager(_DataTypeManager):
|
|
|
145
157
|
strict_types: Optional[Sequence[StrictTypes]] = None,
|
|
146
158
|
use_non_positive_negative_number_constrained_types: bool = False,
|
|
147
159
|
use_union_operator: bool = False,
|
|
160
|
+
use_pendulum: bool = False,
|
|
148
161
|
):
|
|
149
162
|
super().__init__(
|
|
150
163
|
python_version,
|
|
@@ -153,6 +166,7 @@ class DataTypeManager(_DataTypeManager):
|
|
|
153
166
|
strict_types,
|
|
154
167
|
use_non_positive_negative_number_constrained_types,
|
|
155
168
|
use_union_operator,
|
|
169
|
+
use_pendulum,
|
|
156
170
|
)
|
|
157
171
|
|
|
158
172
|
self.type_map: Dict[Types, DataType] = self.type_map_factory(
|
|
@@ -183,7 +197,7 @@ class DataTypeManager(_DataTypeManager):
|
|
|
183
197
|
strict_types: Sequence[StrictTypes],
|
|
184
198
|
pattern_key: str,
|
|
185
199
|
) -> Dict[Types, DataType]:
|
|
186
|
-
return type_map_factory(data_type, strict_types, pattern_key)
|
|
200
|
+
return type_map_factory(data_type, strict_types, pattern_key, self.use_pendulum)
|
|
187
201
|
|
|
188
202
|
def transform_kwargs(
|
|
189
203
|
self, kwargs: Dict[str, Any], filter_: Set[str]
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
{{ decorator }}
|
|
11
11
|
{% endfor -%}
|
|
12
12
|
|
|
13
|
-
class {{ class_name }}({{ base_class }}[{{get_type_hint(fields)}}]):{% if comment is defined %} # {{ comment }}{% endif %}
|
|
13
|
+
class {{ class_name }}({{ base_class }}{%- if fields -%}[{{get_type_hint(fields)}}]{%- endif -%}):{% if comment is defined %} # {{ comment }}{% endif %}
|
|
14
14
|
{%- if description %}
|
|
15
15
|
"""
|
|
16
16
|
{{ description | indent(4) }}
|
|
@@ -58,6 +58,7 @@ class DataTypeManager(_DataTypeManager):
|
|
|
58
58
|
strict_types: Optional[Sequence[StrictTypes]] = None,
|
|
59
59
|
use_non_positive_negative_number_constrained_types: bool = False,
|
|
60
60
|
use_union_operator: bool = False,
|
|
61
|
+
use_pendulum: bool = False,
|
|
61
62
|
):
|
|
62
63
|
super().__init__(
|
|
63
64
|
python_version,
|
|
@@ -66,6 +67,7 @@ class DataTypeManager(_DataTypeManager):
|
|
|
66
67
|
strict_types,
|
|
67
68
|
use_non_positive_negative_number_constrained_types,
|
|
68
69
|
use_union_operator,
|
|
70
|
+
use_pendulum,
|
|
69
71
|
)
|
|
70
72
|
|
|
71
73
|
self.type_map: Dict[Types, DataType] = type_map_factory(
|
|
@@ -390,6 +390,8 @@ class Parser(ABC):
|
|
|
390
390
|
known_third_party: Optional[List[str]] = None,
|
|
391
391
|
custom_formatters: Optional[List[str]] = None,
|
|
392
392
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
393
|
+
use_pendulum: bool = False,
|
|
394
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
393
395
|
) -> None:
|
|
394
396
|
self.data_type_manager: DataTypeManager = data_type_manager_type(
|
|
395
397
|
python_version=target_python_version,
|
|
@@ -397,6 +399,7 @@ class Parser(ABC):
|
|
|
397
399
|
use_generic_container_types=use_generic_container_types,
|
|
398
400
|
strict_types=strict_types,
|
|
399
401
|
use_union_operator=use_union_operator,
|
|
402
|
+
use_pendulum=use_pendulum,
|
|
400
403
|
)
|
|
401
404
|
self.data_model_type: Type[DataModel] = data_model_type
|
|
402
405
|
self.data_model_root_type: Type[DataModel] = data_model_root_type
|
|
@@ -408,19 +411,19 @@ class Parser(ABC):
|
|
|
408
411
|
self.base_class: Optional[str] = base_class
|
|
409
412
|
self.target_python_version: PythonVersion = target_python_version
|
|
410
413
|
self.results: List[DataModel] = []
|
|
411
|
-
self.dump_resolve_reference_action: Optional[
|
|
412
|
-
|
|
413
|
-
|
|
414
|
+
self.dump_resolve_reference_action: Optional[Callable[[Iterable[str]], str]] = (
|
|
415
|
+
dump_resolve_reference_action
|
|
416
|
+
)
|
|
414
417
|
self.validation: bool = validation
|
|
415
418
|
self.field_constraints: bool = field_constraints
|
|
416
419
|
self.snake_case_field: bool = snake_case_field
|
|
417
420
|
self.strip_default_none: bool = strip_default_none
|
|
418
|
-
self.apply_default_values_for_required_fields: (
|
|
419
|
-
|
|
420
|
-
)
|
|
421
|
-
self.force_optional_for_required_fields: (
|
|
422
|
-
|
|
423
|
-
)
|
|
421
|
+
self.apply_default_values_for_required_fields: bool = (
|
|
422
|
+
apply_default_values_for_required_fields
|
|
423
|
+
)
|
|
424
|
+
self.force_optional_for_required_fields: bool = (
|
|
425
|
+
force_optional_for_required_fields
|
|
426
|
+
)
|
|
424
427
|
self.use_schema_description: bool = use_schema_description
|
|
425
428
|
self.use_field_description: bool = use_field_description
|
|
426
429
|
self.use_default_kwarg: bool = use_default_kwarg
|
|
@@ -433,9 +436,9 @@ class Parser(ABC):
|
|
|
433
436
|
self.use_generic_container_types: bool = use_generic_container_types
|
|
434
437
|
self.use_union_operator: bool = use_union_operator
|
|
435
438
|
self.enable_faux_immutability: bool = enable_faux_immutability
|
|
436
|
-
self.custom_class_name_generator: Optional[
|
|
437
|
-
|
|
438
|
-
|
|
439
|
+
self.custom_class_name_generator: Optional[Callable[[str], str]] = (
|
|
440
|
+
custom_class_name_generator
|
|
441
|
+
)
|
|
439
442
|
self.field_extra_keys: Set[str] = field_extra_keys or set()
|
|
440
443
|
self.field_extra_keys_without_x_prefix: Set[str] = (
|
|
441
444
|
field_extra_keys_without_x_prefix or set()
|
|
@@ -490,6 +493,9 @@ class Parser(ABC):
|
|
|
490
493
|
self.class_name: Optional[str] = class_name
|
|
491
494
|
self.wrap_string_literal: Optional[bool] = wrap_string_literal
|
|
492
495
|
self.http_headers: Optional[Sequence[Tuple[str, str]]] = http_headers
|
|
496
|
+
self.http_query_parameters: Optional[Sequence[Tuple[str, str]]] = (
|
|
497
|
+
http_query_parameters
|
|
498
|
+
)
|
|
493
499
|
self.http_ignore_tls: bool = http_ignore_tls
|
|
494
500
|
self.use_annotated: bool = use_annotated
|
|
495
501
|
if self.use_annotated and not self.field_constraints: # pragma: no cover
|
|
@@ -547,7 +553,7 @@ class Parser(ABC):
|
|
|
547
553
|
return self.remote_text_cache.get_or_put(
|
|
548
554
|
url,
|
|
549
555
|
default_factory=lambda url_: get_body(
|
|
550
|
-
url, self.http_headers, self.http_ignore_tls
|
|
556
|
+
url, self.http_headers, self.http_ignore_tls, self.http_query_parameters
|
|
551
557
|
),
|
|
552
558
|
)
|
|
553
559
|
|
|
@@ -568,9 +574,9 @@ class Parser(ABC):
|
|
|
568
574
|
|
|
569
575
|
def __delete_duplicate_models(self, models: List[DataModel]) -> None:
|
|
570
576
|
model_class_names: Dict[str, DataModel] = {}
|
|
571
|
-
model_to_duplicate_models: DefaultDict[
|
|
572
|
-
|
|
573
|
-
|
|
577
|
+
model_to_duplicate_models: DefaultDict[DataModel, List[DataModel]] = (
|
|
578
|
+
defaultdict(list)
|
|
579
|
+
)
|
|
574
580
|
for model in models[:]:
|
|
575
581
|
if isinstance(model, self.data_model_root_type):
|
|
576
582
|
root_data_type = model.fields[0].data_type
|
|
@@ -671,7 +677,8 @@ class Parser(ABC):
|
|
|
671
677
|
for model in models:
|
|
672
678
|
scoped_model_resolver.add(model.path, model.class_name)
|
|
673
679
|
for model in models:
|
|
674
|
-
|
|
680
|
+
before_import = model.imports
|
|
681
|
+
imports.append(before_import)
|
|
675
682
|
for data_type in model.all_data_types:
|
|
676
683
|
# To change from/import
|
|
677
684
|
|
|
@@ -681,7 +688,12 @@ class Parser(ABC):
|
|
|
681
688
|
continue
|
|
682
689
|
|
|
683
690
|
if isinstance(data_type, BaseClassDataType):
|
|
684
|
-
|
|
691
|
+
left, right = relative(model.module_name, data_type.full_name)
|
|
692
|
+
from_ = (
|
|
693
|
+
''.join([left, right])
|
|
694
|
+
if left.endswith('.')
|
|
695
|
+
else '.'.join([left, right])
|
|
696
|
+
)
|
|
685
697
|
import_ = data_type.reference.short_name
|
|
686
698
|
full_path = from_, import_
|
|
687
699
|
else:
|
|
@@ -709,6 +721,9 @@ class Parser(ABC):
|
|
|
709
721
|
reference_path=data_type.reference.path,
|
|
710
722
|
),
|
|
711
723
|
)
|
|
724
|
+
after_import = model.imports
|
|
725
|
+
if before_import != after_import:
|
|
726
|
+
imports.append(after_import)
|
|
712
727
|
|
|
713
728
|
@classmethod
|
|
714
729
|
def __extract_inherited_enum(cls, models: List[DataModel]) -> None:
|
|
@@ -756,7 +771,7 @@ class Parser(ABC):
|
|
|
756
771
|
(pydantic_model.BaseModel, pydantic_model_v2.BaseModel),
|
|
757
772
|
):
|
|
758
773
|
continue # pragma: no cover
|
|
759
|
-
|
|
774
|
+
type_names = []
|
|
760
775
|
if mapping:
|
|
761
776
|
for name, path in mapping.items():
|
|
762
777
|
if (
|
|
@@ -765,10 +780,10 @@ class Parser(ABC):
|
|
|
765
780
|
):
|
|
766
781
|
# TODO: support external reference
|
|
767
782
|
continue
|
|
768
|
-
|
|
783
|
+
type_names.append(name)
|
|
769
784
|
else:
|
|
770
|
-
|
|
771
|
-
if not
|
|
785
|
+
type_names = [discriminator_model.path.split('/')[-1]]
|
|
786
|
+
if not type_names: # pragma: no cover
|
|
772
787
|
raise RuntimeError(
|
|
773
788
|
f'Discriminator type is not found. {data_type.reference.path}'
|
|
774
789
|
)
|
|
@@ -780,7 +795,11 @@ class Parser(ABC):
|
|
|
780
795
|
) != property_name:
|
|
781
796
|
continue
|
|
782
797
|
literals = discriminator_field.data_type.literals
|
|
783
|
-
if
|
|
798
|
+
if (
|
|
799
|
+
len(literals) == 1 and literals[0] == type_names[0]
|
|
800
|
+
if type_names
|
|
801
|
+
else None
|
|
802
|
+
):
|
|
784
803
|
has_one_literal = True
|
|
785
804
|
continue
|
|
786
805
|
for (
|
|
@@ -789,7 +808,7 @@ class Parser(ABC):
|
|
|
789
808
|
if field_data_type.reference: # pragma: no cover
|
|
790
809
|
field_data_type.remove_reference()
|
|
791
810
|
discriminator_field.data_type = self.data_type(
|
|
792
|
-
literals=
|
|
811
|
+
literals=type_names
|
|
793
812
|
)
|
|
794
813
|
discriminator_field.data_type.parent = discriminator_field
|
|
795
814
|
discriminator_field.required = True
|
|
@@ -799,7 +818,7 @@ class Parser(ABC):
|
|
|
799
818
|
discriminator_model.fields.append(
|
|
800
819
|
self.data_model_field_type(
|
|
801
820
|
name=property_name,
|
|
802
|
-
data_type=self.data_type(literals=
|
|
821
|
+
data_type=self.data_type(literals=type_names),
|
|
803
822
|
required=True,
|
|
804
823
|
)
|
|
805
824
|
)
|
|
@@ -1235,6 +1254,7 @@ class Parser(ABC):
|
|
|
1235
1254
|
|
|
1236
1255
|
scoped_model_resolver = ModelResolver()
|
|
1237
1256
|
|
|
1257
|
+
self.__override_required_field(models)
|
|
1238
1258
|
self.__replace_unique_list_to_set(models)
|
|
1239
1259
|
self.__change_from_import(models, imports, scoped_model_resolver, init)
|
|
1240
1260
|
self.__extract_inherited_enum(models)
|
|
@@ -1242,7 +1262,6 @@ class Parser(ABC):
|
|
|
1242
1262
|
self.__reuse_model(models, require_update_action_models)
|
|
1243
1263
|
self.__collapse_root_models(models, unused_models, imports)
|
|
1244
1264
|
self.__set_default_enum_member(models)
|
|
1245
|
-
self.__override_required_field(models)
|
|
1246
1265
|
self.__sort_models(models, imports)
|
|
1247
1266
|
self.__set_one_literal_on_default(models)
|
|
1248
1267
|
self.__apply_discriminator_type(models, imports)
|
|
@@ -156,6 +156,8 @@ class GraphQLParser(Parser):
|
|
|
156
156
|
known_third_party: Optional[List[str]] = None,
|
|
157
157
|
custom_formatters: Optional[List[str]] = None,
|
|
158
158
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
159
|
+
use_pendulum: bool = False,
|
|
160
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
159
161
|
) -> None:
|
|
160
162
|
super().__init__(
|
|
161
163
|
source=source,
|
|
@@ -221,6 +223,8 @@ class GraphQLParser(Parser):
|
|
|
221
223
|
known_third_party=known_third_party,
|
|
222
224
|
custom_formatters=custom_formatters,
|
|
223
225
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
226
|
+
use_pendulum=use_pendulum,
|
|
227
|
+
http_query_parameters=http_query_parameters,
|
|
224
228
|
)
|
|
225
229
|
|
|
226
230
|
self.data_model_scalar_type = data_model_scalar_type
|
|
@@ -118,6 +118,7 @@ json_schema_data_formats: Dict[str, Dict[str, Types]] = {
|
|
|
118
118
|
'date-time': Types.date_time,
|
|
119
119
|
'time': Types.time,
|
|
120
120
|
'password': Types.password,
|
|
121
|
+
'path': Types.path,
|
|
121
122
|
'email': Types.email,
|
|
122
123
|
'idn-email': Types.email,
|
|
123
124
|
'uuid': Types.uuid,
|
|
@@ -437,6 +438,8 @@ class JsonSchemaParser(Parser):
|
|
|
437
438
|
known_third_party: Optional[List[str]] = None,
|
|
438
439
|
custom_formatters: Optional[List[str]] = None,
|
|
439
440
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
441
|
+
use_pendulum: bool = False,
|
|
442
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
440
443
|
) -> None:
|
|
441
444
|
super().__init__(
|
|
442
445
|
source=source,
|
|
@@ -502,6 +505,8 @@ class JsonSchemaParser(Parser):
|
|
|
502
505
|
known_third_party=known_third_party,
|
|
503
506
|
custom_formatters=custom_formatters,
|
|
504
507
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
508
|
+
use_pendulum=use_pendulum,
|
|
509
|
+
http_query_parameters=http_query_parameters,
|
|
505
510
|
)
|
|
506
511
|
|
|
507
512
|
self.remote_object_cache: DefaultPutDict[str, Dict[str, Any]] = DefaultPutDict()
|
|
@@ -632,9 +637,9 @@ class JsonSchemaParser(Parser):
|
|
|
632
637
|
|
|
633
638
|
def set_additional_properties(self, name: str, obj: JsonSchemaObject) -> None:
|
|
634
639
|
if isinstance(obj.additionalProperties, bool):
|
|
635
|
-
self.extra_template_data[name][
|
|
636
|
-
|
|
637
|
-
|
|
640
|
+
self.extra_template_data[name]['additionalProperties'] = (
|
|
641
|
+
obj.additionalProperties
|
|
642
|
+
)
|
|
638
643
|
|
|
639
644
|
def set_title(self, name: str, obj: JsonSchemaObject) -> None:
|
|
640
645
|
if obj.title:
|
|
@@ -220,6 +220,8 @@ class OpenAPIParser(JsonSchemaParser):
|
|
|
220
220
|
known_third_party: Optional[List[str]] = None,
|
|
221
221
|
custom_formatters: Optional[List[str]] = None,
|
|
222
222
|
custom_formatters_kwargs: Optional[Dict[str, Any]] = None,
|
|
223
|
+
use_pendulum: bool = False,
|
|
224
|
+
http_query_parameters: Optional[Sequence[Tuple[str, str]]] = None,
|
|
223
225
|
):
|
|
224
226
|
super().__init__(
|
|
225
227
|
source=source,
|
|
@@ -285,6 +287,8 @@ class OpenAPIParser(JsonSchemaParser):
|
|
|
285
287
|
known_third_party=known_third_party,
|
|
286
288
|
custom_formatters=custom_formatters,
|
|
287
289
|
custom_formatters_kwargs=custom_formatters_kwargs,
|
|
290
|
+
use_pendulum=use_pendulum,
|
|
291
|
+
http_query_parameters=http_query_parameters,
|
|
288
292
|
)
|
|
289
293
|
self.open_api_scopes: List[OpenAPIScope] = openapi_scopes or [
|
|
290
294
|
OpenAPIScope.Schemas
|
|
@@ -548,6 +548,7 @@ class Types(Enum):
|
|
|
548
548
|
date = auto()
|
|
549
549
|
date_time = auto()
|
|
550
550
|
password = auto()
|
|
551
|
+
path = auto()
|
|
551
552
|
email = auto()
|
|
552
553
|
uuid = auto()
|
|
553
554
|
uuid1 = auto()
|
|
@@ -577,6 +578,7 @@ class DataTypeManager(ABC):
|
|
|
577
578
|
strict_types: Optional[Sequence[StrictTypes]] = None,
|
|
578
579
|
use_non_positive_negative_number_constrained_types: bool = False,
|
|
579
580
|
use_union_operator: bool = False,
|
|
581
|
+
use_pendulum: bool = False,
|
|
580
582
|
) -> None:
|
|
581
583
|
self.python_version = python_version
|
|
582
584
|
self.use_standard_collections: bool = use_standard_collections
|
|
@@ -586,6 +588,7 @@ class DataTypeManager(ABC):
|
|
|
586
588
|
use_non_positive_negative_number_constrained_types
|
|
587
589
|
)
|
|
588
590
|
self.use_union_operator: bool = use_union_operator
|
|
591
|
+
self.use_pendulum: bool = use_pendulum
|
|
589
592
|
|
|
590
593
|
if (
|
|
591
594
|
use_generic_container_types and python_version == PythonVersion.PY_36
|
datamodel_code_generator/util.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
version: str = '0.25.
|
|
1
|
+
version: str = '0.25.6'
|
{datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datamodel-code-generator
|
|
3
|
-
Version: 0.25.
|
|
3
|
+
Version: 0.25.6
|
|
4
4
|
Summary: Datamodel Code Generator
|
|
5
5
|
Home-page: https://github.com/koxudaxi/datamodel-code-generator
|
|
6
6
|
License: MIT
|
|
@@ -376,6 +376,9 @@ Options:
|
|
|
376
376
|
(example: "Authorization: Basic dXNlcjpwYXNz")
|
|
377
377
|
--http-ignore-tls Disable verification of the remote host's TLS
|
|
378
378
|
certificate
|
|
379
|
+
--http-query-parameters QUERY_PARAMETER [QUERY_PARAMETER ...]
|
|
380
|
+
Set query parameters in HTTP requests to the remote host.
|
|
381
|
+
(example: "ref=branch")
|
|
379
382
|
--input INPUT Input file/directory (default: stdin)
|
|
380
383
|
--input-file-type {auto,openapi,graphql,jsonschema,json,yaml,dict,csv}
|
|
381
384
|
Input file type (default: auto)
|
|
@@ -447,6 +450,9 @@ Field customization:
|
|
|
447
450
|
Fields that have default values.
|
|
448
451
|
--use-field-description
|
|
449
452
|
Use schema description to populate field docstring
|
|
453
|
+
--use-pendulum
|
|
454
|
+
Use pendulum instead of `datetime` for `date`,
|
|
455
|
+
`datetime`, and `time` data types
|
|
450
456
|
|
|
451
457
|
Model customization:
|
|
452
458
|
--allow-extra-fields Allow to pass extra fields, if this flag is not
|
{datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/RECORD
RENAMED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
datamodel_code_generator/__init__.py,sha256=
|
|
2
|
-
datamodel_code_generator/__main__.py,sha256=
|
|
3
|
-
datamodel_code_generator/arguments.py,sha256=
|
|
4
|
-
datamodel_code_generator/format.py,sha256=
|
|
5
|
-
datamodel_code_generator/http.py,sha256=
|
|
6
|
-
datamodel_code_generator/imports.py,sha256=
|
|
1
|
+
datamodel_code_generator/__init__.py,sha256=zqe2mCNMAgFm9BGJHz8yTAVYVdK30Gt_pOnN7CjKvx4,17951
|
|
2
|
+
datamodel_code_generator/__main__.py,sha256=klyeTja8UY57kcMvWXSp6aEOtNAOCX_biB0sqsCLFfE,19483
|
|
3
|
+
datamodel_code_generator/arguments.py,sha256=kjTIK3mqF7fU5hJ0ZA-3axudgKjpkypLGsc4HikHqFQ,14941
|
|
4
|
+
datamodel_code_generator/format.py,sha256=yTSOf3-jUO4X5NOljAjm-4xYC_uBJV3-RLXUYIvw-yw,8595
|
|
5
|
+
datamodel_code_generator/http.py,sha256=CwLVnXO4_W_fWKJsHnJp6Q_3GuF3qjCjeAe48Ihawrs,714
|
|
6
|
+
datamodel_code_generator/imports.py,sha256=zswV5jMxWwr1-UO0beiyHT9ykhTYGnMTLtTQ6YVougQ,5529
|
|
7
7
|
datamodel_code_generator/model/__init__.py,sha256=A0CqnL87-lY_Te-n-99ya5v7h6l4jE6hOPP_itvcWOc,3091
|
|
8
|
-
datamodel_code_generator/model/base.py,sha256=
|
|
8
|
+
datamodel_code_generator/model/base.py,sha256=M1T8L7how4nW0aqGuunzc1LyWVSJ3OuFvRnx1Ig13hA,14019
|
|
9
9
|
datamodel_code_generator/model/dataclass.py,sha256=9meJNWb-XPYYO8kDMSLhSfO6fulGWV7r3_XIM5kA71M,3965
|
|
10
10
|
datamodel_code_generator/model/enum.py,sha256=Giehhtij2DZs2LssSJnG_CIIHsSA7Mkz471GU-Cb5kI,3338
|
|
11
11
|
datamodel_code_generator/model/imports.py,sha256=9-0bd-DvZRjZkWMsmw-gykL8fzTd6M-vQEqS7Rm_ty4,725
|
|
12
|
-
datamodel_code_generator/model/msgspec.py,sha256=
|
|
12
|
+
datamodel_code_generator/model/msgspec.py,sha256=jSeOGIytvOleK7MHBxr6MVX9JwsFKSQ7z4aKwcOTuOc,8954
|
|
13
13
|
datamodel_code_generator/model/pydantic/__init__.py,sha256=AYMjDCtnV4vweYqe1asTRCYdOo8IGLBhd8pEdxyY8ok,1372
|
|
14
14
|
datamodel_code_generator/model/pydantic/base_model.py,sha256=Y2GSlcLBvQh8hrlwGE3rGLTsQLKxERBts0so5BcUP6Y,11970
|
|
15
15
|
datamodel_code_generator/model/pydantic/custom_root_type.py,sha256=XOeJqzUEAYE21C3hPAnRIz9iDWIjZvUOWDc9MCrpdvw,299
|
|
16
16
|
datamodel_code_generator/model/pydantic/dataclass.py,sha256=sbqTmutl8Fjf1pYngfdv0NMXt904QcTRpHqmZy6GUiQ,424
|
|
17
17
|
datamodel_code_generator/model/pydantic/imports.py,sha256=2nSLYwphBUMQEa0PTSNwoLjEBslu02EQb6BdZ-S51yk,2189
|
|
18
|
-
datamodel_code_generator/model/pydantic/types.py,sha256=
|
|
18
|
+
datamodel_code_generator/model/pydantic/types.py,sha256=GDh1KRforpUIj58TSLSqrbKRnXi8O1qfHT8NaoUYvME,13034
|
|
19
19
|
datamodel_code_generator/model/pydantic_v2/__init__.py,sha256=ahhh9sRT9d032dG5gf14M4Q-8MC3P2rQ5Ngo7v_uB6A,865
|
|
20
20
|
datamodel_code_generator/model/pydantic_v2/base_model.py,sha256=ed4wP_DkrsafPh5Clt1wccel9svggJ8MXKy8w1jCQDs,7596
|
|
21
21
|
datamodel_code_generator/model/pydantic_v2/imports.py,sha256=Q6XC6iE5v4LJvQ2DOXDGFtR-FnGPsaZ56KiiTiF2bIE,191
|
|
@@ -37,23 +37,23 @@ datamodel_code_generator/model/template/pydantic/Config.jinja2,sha256=Ik028qdqQh
|
|
|
37
37
|
datamodel_code_generator/model/template/pydantic/dataclass.jinja2,sha256=hM4OZTVhtOokqlPNSdh5drhBXfQLPvbyO88jipSPr5Y,629
|
|
38
38
|
datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=6Swz3U3vYFGnTFY85SGTmsNUflcJI61oxdz2CgPKaDk,1091
|
|
39
39
|
datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2,sha256=xHvBYrh__32O1xRCSl6_u5zbyYIjB8a5k8fZiTo0spY,149
|
|
40
|
-
datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2,sha256=
|
|
40
|
+
datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2,sha256=XQBlML7Hm5hN6_AExENNvVc_yxNWijcIfTTbbmegCpE,1223
|
|
41
41
|
datamodel_code_generator/model/template/root.jinja2,sha256=3OTtibxLcGA-FMdR0QDCJUJQgf_kRW0OafeCTPFSFFo,162
|
|
42
42
|
datamodel_code_generator/model/typed_dict.py,sha256=pzUaKLaVDF5rfxAaR1m4FqnhR00eE6AIP30oGTj67fY,4717
|
|
43
|
-
datamodel_code_generator/model/types.py,sha256=
|
|
43
|
+
datamodel_code_generator/model/types.py,sha256=Ti3cEtRQpBYgC4Y5ocAn6Ol-ZbnKG_P7C0nHBX9KtV8,2953
|
|
44
44
|
datamodel_code_generator/model/union.py,sha256=loaVWQi-UHkV4gLfF2JhxLcgZRMsejaoJzGvjTlp_bo,1716
|
|
45
45
|
datamodel_code_generator/parser/__init__.py,sha256=zHbw6RPlJC0SAQjb-XyVlyZhcOu5PfYgPidy6jlUM8M,793
|
|
46
|
-
datamodel_code_generator/parser/base.py,sha256=
|
|
47
|
-
datamodel_code_generator/parser/graphql.py,sha256=
|
|
48
|
-
datamodel_code_generator/parser/jsonschema.py,sha256=
|
|
49
|
-
datamodel_code_generator/parser/openapi.py,sha256=
|
|
46
|
+
datamodel_code_generator/parser/base.py,sha256=jGfXtKnLA-_38aXrktTReu07KMHuTswmjZtgyxjC21c,53535
|
|
47
|
+
datamodel_code_generator/parser/graphql.py,sha256=n1AEOoJRbmK4Oq3_4M3VgvMaC12e3zBXFMXVrO-d2kI,20594
|
|
48
|
+
datamodel_code_generator/parser/jsonschema.py,sha256=S0_lBs39XgP6YXNaUGSaMD8JSxiqO1NJzP6uniYzWms,69499
|
|
49
|
+
datamodel_code_generator/parser/openapi.py,sha256=bGLWGbFysBq4CtM-piuHero_EKW_T0-CS8miEj3Trqw,25623
|
|
50
50
|
datamodel_code_generator/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
51
51
|
datamodel_code_generator/reference.py,sha256=EoalUNUP5us31bfMrHDa1iiKqxL8gHrpZKY_IxgZrOg,26347
|
|
52
|
-
datamodel_code_generator/types.py,sha256=
|
|
53
|
-
datamodel_code_generator/util.py,sha256=
|
|
54
|
-
datamodel_code_generator/version.py,sha256=
|
|
55
|
-
datamodel_code_generator-0.25.
|
|
56
|
-
datamodel_code_generator-0.25.
|
|
57
|
-
datamodel_code_generator-0.25.
|
|
58
|
-
datamodel_code_generator-0.25.
|
|
59
|
-
datamodel_code_generator-0.25.
|
|
52
|
+
datamodel_code_generator/types.py,sha256=xPFX0NkgPz5CEz_yqKkZa7wPFr08P0e7X4Ooheoo2Uo,19652
|
|
53
|
+
datamodel_code_generator/util.py,sha256=Lrjj20mmma4Glpfs42sCoGpt1cncalgUGyNZZviqWdU,3692
|
|
54
|
+
datamodel_code_generator/version.py,sha256=EsEWIq40wgO8zhAb88MflW4YdfaOV5E5p5Do3pE8JVU,24
|
|
55
|
+
datamodel_code_generator-0.25.6.dist-info/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
|
|
56
|
+
datamodel_code_generator-0.25.6.dist-info/METADATA,sha256=k5NXlsOhdi6Xh59kHw-Od8CsY5fMN8qhKoPmMEElCwQ,23339
|
|
57
|
+
datamodel_code_generator-0.25.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
58
|
+
datamodel_code_generator-0.25.6.dist-info/entry_points.txt,sha256=bykbUWqOCiKfxJPGe8jpNqTqD1NG7uyRmozdnwzu7rk,76
|
|
59
|
+
datamodel_code_generator-0.25.6.dist-info/RECORD,,
|
{datamodel_code_generator-0.25.4.dist-info → datamodel_code_generator-0.25.6.dist-info}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|