datamodel-code-generator 0.30.2__py3-none-any.whl → 0.31.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 +2 -0
- datamodel_code_generator/__main__.py +2 -0
- datamodel_code_generator/arguments.py +10 -2
- datamodel_code_generator/model/pydantic/__init__.py +1 -0
- datamodel_code_generator/model/pydantic/base_model.py +12 -4
- datamodel_code_generator/model/pydantic_v2/__init__.py +1 -0
- datamodel_code_generator/parser/base.py +5 -1
- datamodel_code_generator/parser/graphql.py +2 -0
- datamodel_code_generator/parser/jsonschema.py +2 -0
- datamodel_code_generator/parser/openapi.py +2 -0
- {datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/METADATA +6 -3
- {datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/RECORD +15 -15
- {datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/WHEEL +0 -0
- {datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/entry_points.txt +0 -0
- {datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -233,6 +233,7 @@ def generate( # noqa: PLR0912, PLR0913, PLR0914, PLR0915
|
|
|
233
233
|
enable_version_header: bool = False,
|
|
234
234
|
allow_population_by_field_name: bool = False,
|
|
235
235
|
allow_extra_fields: bool = False,
|
|
236
|
+
extra_fields: str | None = None,
|
|
236
237
|
apply_default_values_for_required_fields: bool = False,
|
|
237
238
|
force_optional_for_required_fields: bool = False,
|
|
238
239
|
class_name: str | None = None,
|
|
@@ -428,6 +429,7 @@ def generate( # noqa: PLR0912, PLR0913, PLR0914, PLR0915
|
|
|
428
429
|
aliases=aliases,
|
|
429
430
|
allow_population_by_field_name=allow_population_by_field_name,
|
|
430
431
|
allow_extra_fields=allow_extra_fields,
|
|
432
|
+
extra_fields=extra_fields,
|
|
431
433
|
apply_default_values_for_required_fields=apply_default_values_for_required_fields,
|
|
432
434
|
force_optional_for_required_fields=force_optional_for_required_fields,
|
|
433
435
|
class_name=class_name,
|
|
@@ -261,6 +261,7 @@ class Config(BaseModel):
|
|
|
261
261
|
enable_version_header: bool = False
|
|
262
262
|
allow_population_by_field_name: bool = False
|
|
263
263
|
allow_extra_fields: bool = False
|
|
264
|
+
extra_fields: Optional[str] = None # noqa: UP045
|
|
264
265
|
use_default: bool = False
|
|
265
266
|
force_optional: bool = False
|
|
266
267
|
class_name: Optional[str] = None # noqa: UP045
|
|
@@ -475,6 +476,7 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
|
|
|
475
476
|
enable_version_header=config.enable_version_header,
|
|
476
477
|
allow_population_by_field_name=config.allow_population_by_field_name,
|
|
477
478
|
allow_extra_fields=config.allow_extra_fields,
|
|
479
|
+
extra_fields=config.extra_fields,
|
|
478
480
|
apply_default_values_for_required_fields=config.use_default,
|
|
479
481
|
force_optional_for_required_fields=config.force_optional,
|
|
480
482
|
class_name=config.class_name,
|
|
@@ -43,6 +43,7 @@ base_options = arg_parser.add_argument_group("Options")
|
|
|
43
43
|
typing_options = arg_parser.add_argument_group("Typing customization")
|
|
44
44
|
field_options = arg_parser.add_argument_group("Field customization")
|
|
45
45
|
model_options = arg_parser.add_argument_group("Model customization")
|
|
46
|
+
extra_fields_model_options = model_options.add_mutually_exclusive_group()
|
|
46
47
|
template_options = arg_parser.add_argument_group("Template customization")
|
|
47
48
|
openapi_options = arg_parser.add_argument_group("OpenAPI-only options")
|
|
48
49
|
general_options = arg_parser.add_argument_group("General options")
|
|
@@ -94,9 +95,10 @@ base_options.add_argument(
|
|
|
94
95
|
# ======================================================================================
|
|
95
96
|
# Customization options for generated models
|
|
96
97
|
# ======================================================================================
|
|
97
|
-
|
|
98
|
+
extra_fields_model_options.add_argument(
|
|
98
99
|
"--allow-extra-fields",
|
|
99
|
-
help="Allow passing extra fields, if this flag is not passed, extra fields are forbidden."
|
|
100
|
+
help="Deprecated: Allow passing extra fields, if this flag is not passed, extra fields are forbidden. "
|
|
101
|
+
"This flag is deprecated. Use `--extra-fields=allow` instead.",
|
|
100
102
|
action="store_true",
|
|
101
103
|
default=None,
|
|
102
104
|
)
|
|
@@ -141,6 +143,12 @@ model_options.add_argument(
|
|
|
141
143
|
action="store_true",
|
|
142
144
|
default=None,
|
|
143
145
|
)
|
|
146
|
+
extra_fields_model_options.add_argument(
|
|
147
|
+
"--extra-fields",
|
|
148
|
+
help="Set the generated models to allow, forbid, or ignore extra fields.",
|
|
149
|
+
choices=["allow", "ignore", "forbid"],
|
|
150
|
+
default=None,
|
|
151
|
+
)
|
|
144
152
|
model_options.add_argument(
|
|
145
153
|
"--keep-model-order",
|
|
146
154
|
help="Keep generated models' order",
|
|
@@ -22,6 +22,7 @@ class Config(_BaseModel):
|
|
|
22
22
|
title: Optional[str] = None # noqa: UP045
|
|
23
23
|
allow_population_by_field_name: Optional[bool] = None # noqa: UP045
|
|
24
24
|
allow_extra_fields: Optional[bool] = None # noqa: UP045
|
|
25
|
+
extra_fields: Optional[str] = None # noqa: UP045
|
|
25
26
|
allow_mutation: Optional[bool] = None # noqa: UP045
|
|
26
27
|
arbitrary_types_allowed: Optional[bool] = None # noqa: UP045
|
|
27
28
|
orm_mode: Optional[bool] = None # noqa: UP045
|
|
@@ -286,12 +286,20 @@ class BaseModel(BaseModelBase):
|
|
|
286
286
|
|
|
287
287
|
additional_properties = self.extra_template_data.get("additionalProperties")
|
|
288
288
|
allow_extra_fields = self.extra_template_data.get("allow_extra_fields")
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
)
|
|
289
|
+
extra_fields = self.extra_template_data.get("extra_fields")
|
|
290
|
+
|
|
291
|
+
if allow_extra_fields or extra_fields or additional_properties is not None:
|
|
293
292
|
self._additional_imports.append(IMPORT_EXTRA)
|
|
294
293
|
|
|
294
|
+
if allow_extra_fields:
|
|
295
|
+
config_parameters["extra"] = "Extra.allow"
|
|
296
|
+
elif extra_fields:
|
|
297
|
+
config_parameters["extra"] = f"Extra.{extra_fields}"
|
|
298
|
+
elif additional_properties is True:
|
|
299
|
+
config_parameters["extra"] = "Extra.allow"
|
|
300
|
+
elif additional_properties is False:
|
|
301
|
+
config_parameters["extra"] = "Extra.forbid"
|
|
302
|
+
|
|
295
303
|
for config_attribute in "allow_population_by_field_name", "allow_mutation":
|
|
296
304
|
if config_attribute in self.extra_template_data:
|
|
297
305
|
config_parameters[config_attribute] = self.extra_template_data[config_attribute]
|
|
@@ -21,6 +21,7 @@ class ConfigDict(_BaseModel):
|
|
|
21
21
|
title: Optional[str] = None # noqa: UP045
|
|
22
22
|
populate_by_name: Optional[bool] = None # noqa: UP045
|
|
23
23
|
allow_extra_fields: Optional[bool] = None # noqa: UP045
|
|
24
|
+
extra_fields: Optional[str] = None # noqa: UP045
|
|
24
25
|
from_attributes: Optional[bool] = None # noqa: UP045
|
|
25
26
|
frozen: Optional[bool] = None # noqa: UP045
|
|
26
27
|
arbitrary_types_allowed: Optional[bool] = None # noqa: UP045
|
|
@@ -326,6 +326,7 @@ class Parser(ABC):
|
|
|
326
326
|
allow_population_by_field_name: bool = False,
|
|
327
327
|
apply_default_values_for_required_fields: bool = False,
|
|
328
328
|
allow_extra_fields: bool = False,
|
|
329
|
+
extra_fields: str | None = None,
|
|
329
330
|
force_optional_for_required_fields: bool = False,
|
|
330
331
|
class_name: str | None = None,
|
|
331
332
|
use_standard_collections: bool = False,
|
|
@@ -452,6 +453,9 @@ class Parser(ABC):
|
|
|
452
453
|
if allow_extra_fields:
|
|
453
454
|
self.extra_template_data[ALL_MODEL]["allow_extra_fields"] = True
|
|
454
455
|
|
|
456
|
+
if extra_fields:
|
|
457
|
+
self.extra_template_data[ALL_MODEL]["extra_fields"] = extra_fields
|
|
458
|
+
|
|
455
459
|
if enable_faux_immutability:
|
|
456
460
|
self.extra_template_data[ALL_MODEL]["allow_mutation"] = False
|
|
457
461
|
|
|
@@ -1135,7 +1139,7 @@ class Parser(ABC):
|
|
|
1135
1139
|
if self.data_model_type != pydantic_model_v2.BaseModel:
|
|
1136
1140
|
return
|
|
1137
1141
|
for model in models:
|
|
1138
|
-
if model.base_class
|
|
1142
|
+
if "Enum" in model.base_class:
|
|
1139
1143
|
continue
|
|
1140
1144
|
|
|
1141
1145
|
for field in model.fields:
|
|
@@ -102,6 +102,7 @@ class GraphQLParser(Parser):
|
|
|
102
102
|
allow_population_by_field_name: bool = False,
|
|
103
103
|
apply_default_values_for_required_fields: bool = False,
|
|
104
104
|
allow_extra_fields: bool = False,
|
|
105
|
+
extra_fields: str | None = None,
|
|
105
106
|
force_optional_for_required_fields: bool = False,
|
|
106
107
|
class_name: str | None = None,
|
|
107
108
|
use_standard_collections: bool = False,
|
|
@@ -177,6 +178,7 @@ class GraphQLParser(Parser):
|
|
|
177
178
|
aliases=aliases,
|
|
178
179
|
allow_population_by_field_name=allow_population_by_field_name,
|
|
179
180
|
allow_extra_fields=allow_extra_fields,
|
|
181
|
+
extra_fields=extra_fields,
|
|
180
182
|
apply_default_values_for_required_fields=apply_default_values_for_required_fields,
|
|
181
183
|
force_optional_for_required_fields=force_optional_for_required_fields,
|
|
182
184
|
class_name=class_name,
|
|
@@ -381,6 +381,7 @@ class JsonSchemaParser(Parser):
|
|
|
381
381
|
allow_population_by_field_name: bool = False,
|
|
382
382
|
apply_default_values_for_required_fields: bool = False,
|
|
383
383
|
allow_extra_fields: bool = False,
|
|
384
|
+
extra_fields: str | None = None,
|
|
384
385
|
force_optional_for_required_fields: bool = False,
|
|
385
386
|
class_name: str | None = None,
|
|
386
387
|
use_standard_collections: bool = False,
|
|
@@ -456,6 +457,7 @@ class JsonSchemaParser(Parser):
|
|
|
456
457
|
aliases=aliases,
|
|
457
458
|
allow_population_by_field_name=allow_population_by_field_name,
|
|
458
459
|
allow_extra_fields=allow_extra_fields,
|
|
460
|
+
extra_fields=extra_fields,
|
|
459
461
|
apply_default_values_for_required_fields=apply_default_values_for_required_fields,
|
|
460
462
|
force_optional_for_required_fields=force_optional_for_required_fields,
|
|
461
463
|
class_name=class_name,
|
|
@@ -162,6 +162,7 @@ class OpenAPIParser(JsonSchemaParser):
|
|
|
162
162
|
aliases: Mapping[str, str] | None = None,
|
|
163
163
|
allow_population_by_field_name: bool = False,
|
|
164
164
|
allow_extra_fields: bool = False,
|
|
165
|
+
extra_fields: str | None = None,
|
|
165
166
|
apply_default_values_for_required_fields: bool = False,
|
|
166
167
|
force_optional_for_required_fields: bool = False,
|
|
167
168
|
class_name: str | None = None,
|
|
@@ -239,6 +240,7 @@ class OpenAPIParser(JsonSchemaParser):
|
|
|
239
240
|
aliases=aliases,
|
|
240
241
|
allow_population_by_field_name=allow_population_by_field_name,
|
|
241
242
|
allow_extra_fields=allow_extra_fields,
|
|
243
|
+
extra_fields=extra_fields,
|
|
242
244
|
apply_default_values_for_required_fields=apply_default_values_for_required_fields,
|
|
243
245
|
force_optional_for_required_fields=force_optional_for_required_fields,
|
|
244
246
|
class_name=class_name,
|
{datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datamodel-code-generator
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.31.0
|
|
4
4
|
Summary: Datamodel Code Generator
|
|
5
5
|
Project-URL: Homepage, https://github.com/koxudaxi/datamodel-code-generator
|
|
6
6
|
Project-URL: Source, https://github.com/koxudaxi/datamodel-code-generator
|
|
@@ -489,8 +489,9 @@ Field customization:
|
|
|
489
489
|
Use schema description to populate field docstring
|
|
490
490
|
|
|
491
491
|
Model customization:
|
|
492
|
-
--allow-extra-fields Allow passing extra fields, if this flag is not passed,
|
|
493
|
-
are forbidden.
|
|
492
|
+
--allow-extra-fields Deprecated: Allow passing extra fields, if this flag is not passed,
|
|
493
|
+
extra fields are forbidden. This flag is deprecated. Use `--extra-
|
|
494
|
+
fields=allow` instead.
|
|
494
495
|
--allow-population-by-field-name
|
|
495
496
|
Allow population by field name
|
|
496
497
|
--class-name CLASS_NAME
|
|
@@ -505,6 +506,8 @@ Model customization:
|
|
|
505
506
|
Enable faux immutability
|
|
506
507
|
--enable-version-header
|
|
507
508
|
Enable package version on file headers
|
|
509
|
+
--extra-fields {allow,ignore,forbid}
|
|
510
|
+
Set the generated models to allow, forbid, or ignore extra fields.
|
|
508
511
|
--frozen-dataclasses Generate frozen dataclasses (dataclass(frozen=True)). Only applies
|
|
509
512
|
to dataclass output.
|
|
510
513
|
--keep-model-order Keep generated models'' order
|
{datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/RECORD
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
datamodel_code_generator/__init__.py,sha256=
|
|
2
|
-
datamodel_code_generator/__main__.py,sha256=
|
|
3
|
-
datamodel_code_generator/arguments.py,sha256=
|
|
1
|
+
datamodel_code_generator/__init__.py,sha256=H6ZnGum3Xw1u1o2e7a6gLjA09Vm2DlXo_Vm8GRrTUlY,20602
|
|
2
|
+
datamodel_code_generator/__main__.py,sha256=Z9g_NGrnxV63MRuqtUUpPW48felXmVxwGBtWWkgNlj4,22803
|
|
3
|
+
datamodel_code_generator/arguments.py,sha256=vGNwaq0B3Lchi30Uh1Lt-MBdkEW2nW2PwDQrmrpLKxA,17210
|
|
4
4
|
datamodel_code_generator/format.py,sha256=ZlnTCAl1H4og685smvCBSzexgpYbZtyYLIrt7lwUNcY,8934
|
|
5
5
|
datamodel_code_generator/http.py,sha256=LE94GC7I9D8lWIg_YAGWedfy0XNxOXTmiYKuNMTwouo,887
|
|
6
6
|
datamodel_code_generator/imports.py,sha256=Nq83WbEGCegntg3WX4VbKfzAIs84alZ7IrYyNPrlUbc,5517
|
|
@@ -20,13 +20,13 @@ datamodel_code_generator/model/scalar.py,sha256=xfONEK30eYJ2mSL9PK9zXqEG5-xApYMI
|
|
|
20
20
|
datamodel_code_generator/model/typed_dict.py,sha256=FJi_fEZWuFe3nvidfl-jqr9PMRFTvfusoEFQkx1BqHI,4685
|
|
21
21
|
datamodel_code_generator/model/types.py,sha256=ZyEwi76EBI5RS5JfoNUoRHmjOAZDup8oNFvQQDizfwQ,3502
|
|
22
22
|
datamodel_code_generator/model/union.py,sha256=zwq1ayGFW3KbI4SxPCcdZcrM7X4Px25IdujDedtwgOw,1929
|
|
23
|
-
datamodel_code_generator/model/pydantic/__init__.py,sha256=
|
|
24
|
-
datamodel_code_generator/model/pydantic/base_model.py,sha256=
|
|
23
|
+
datamodel_code_generator/model/pydantic/__init__.py,sha256=ggJNv7_6Vv-BgY50O-0Pa6IHGavkxGAjSa9lLEmFOnE,1149
|
|
24
|
+
datamodel_code_generator/model/pydantic/base_model.py,sha256=0ZsoQfjhhRTMlvsThGEsXJgYMubjrakkuOHUt5-f6HY,12492
|
|
25
25
|
datamodel_code_generator/model/pydantic/custom_root_type.py,sha256=VJpEAmGFe3TzMKrR5YvR7PJ3pfGHcYytO1zhQrWyoWg,299
|
|
26
26
|
datamodel_code_generator/model/pydantic/dataclass.py,sha256=jgjkqQk71CQP4RbTcPGSEOQDNqjTQnzFavvl5LjWTBw,455
|
|
27
27
|
datamodel_code_generator/model/pydantic/imports.py,sha256=nWPiLgDeYNPHcAs8M-gaUUZg1daQRHdBPpjYuX3b5u4,2225
|
|
28
28
|
datamodel_code_generator/model/pydantic/types.py,sha256=ttTiDsQ6FV3h4C_NTEhvPUmUpeqxBNQt-DJJFpKZS8s,13356
|
|
29
|
-
datamodel_code_generator/model/pydantic_v2/__init__.py,sha256=
|
|
29
|
+
datamodel_code_generator/model/pydantic_v2/__init__.py,sha256=YHfOs8prPBsrQmYm0kJATSyU0wafQTqKNd24e2-KGJE,1344
|
|
30
30
|
datamodel_code_generator/model/pydantic_v2/base_model.py,sha256=J_DxR6Auw0L-zHn0F5l9K8XtSmfEvDT26Bj-VZxihiE,8353
|
|
31
31
|
datamodel_code_generator/model/pydantic_v2/imports.py,sha256=K3XD2kF9YCKmo5_7b2ipV5bGUrjz0avS-SiyDMVIpF0,299
|
|
32
32
|
datamodel_code_generator/model/pydantic_v2/root_model.py,sha256=H4rwtg56N65-I3QHlPvlNhDcSPV0m56KSAgfGmxYXAQ,888
|
|
@@ -48,12 +48,12 @@ datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=i1Wg
|
|
|
48
48
|
datamodel_code_generator/model/template/pydantic_v2/ConfigDict.jinja2,sha256=xHvBYrh__32O1xRCSl6_u5zbyYIjB8a5k8fZiTo0spY,149
|
|
49
49
|
datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2,sha256=XQBlML7Hm5hN6_AExENNvVc_yxNWijcIfTTbbmegCpE,1223
|
|
50
50
|
datamodel_code_generator/parser/__init__.py,sha256=3XtFcDPocaetfjmWFqj_CubqNCDipb7vXZHsYKdJXXU,851
|
|
51
|
-
datamodel_code_generator/parser/base.py,sha256=
|
|
52
|
-
datamodel_code_generator/parser/graphql.py,sha256=
|
|
53
|
-
datamodel_code_generator/parser/jsonschema.py,sha256=
|
|
54
|
-
datamodel_code_generator/parser/openapi.py,sha256=
|
|
55
|
-
datamodel_code_generator-0.
|
|
56
|
-
datamodel_code_generator-0.
|
|
57
|
-
datamodel_code_generator-0.
|
|
58
|
-
datamodel_code_generator-0.
|
|
59
|
-
datamodel_code_generator-0.
|
|
51
|
+
datamodel_code_generator/parser/base.py,sha256=4B4UeEjCfl_IdRak_qi5Wx8sUx5bX8Xt-Z0CmfsWsks,62940
|
|
52
|
+
datamodel_code_generator/parser/graphql.py,sha256=TNLxy-0wWJSpCm6HK5fKooZdaJodcwQqVr0J29ao3J8,23330
|
|
53
|
+
datamodel_code_generator/parser/jsonschema.py,sha256=oFSZOyLL3K0tneH09t2lNKdWcbmR_r5OjCyWKPq2Jxc,71114
|
|
54
|
+
datamodel_code_generator/parser/openapi.py,sha256=kI4kqVBG96rdAVb8z0l4gF6QpcylgVoGjlK_-KToZRg,27607
|
|
55
|
+
datamodel_code_generator-0.31.0.dist-info/METADATA,sha256=4pJIEOpNG7M2YhWpZi8OjNBSD0KO6UFIelQNRjIkSg0,25658
|
|
56
|
+
datamodel_code_generator-0.31.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
57
|
+
datamodel_code_generator-0.31.0.dist-info/entry_points.txt,sha256=cJVcHiEViQMANaoM5C1xR5hzmyCqH6hHHMpV8W00in8,77
|
|
58
|
+
datamodel_code_generator-0.31.0.dist-info/licenses/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
|
|
59
|
+
datamodel_code_generator-0.31.0.dist-info/RECORD,,
|
{datamodel_code_generator-0.30.2.dist-info → datamodel_code_generator-0.31.0.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|