datamodel-code-generator 0.28.5__py3-none-any.whl → 0.29.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 +1 -0
- datamodel_code_generator/__main__.py +11 -9
- datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 +10 -0
- datamodel_code_generator/parser/base.py +28 -5
- {datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/METADATA +2 -2
- {datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/RECORD +9 -9
- {datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/WHEEL +0 -0
- {datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/entry_points.txt +0 -0
- {datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -329,7 +329,7 @@ class Config(BaseModel):
|
|
|
329
329
|
setattr(self, field_name, getattr(parsed_args, field_name))
|
|
330
330
|
|
|
331
331
|
|
|
332
|
-
def _get_pyproject_toml_config(source: Path) -> dict[str, Any]
|
|
332
|
+
def _get_pyproject_toml_config(source: Path) -> dict[str, Any]:
|
|
333
333
|
"""Find and return the [tool.datamodel-codgen] section of the closest
|
|
334
334
|
pyproject.toml if it exists.
|
|
335
335
|
"""
|
|
@@ -339,14 +339,20 @@ def _get_pyproject_toml_config(source: Path) -> dict[str, Any] | None:
|
|
|
339
339
|
if (current_path / "pyproject.toml").is_file():
|
|
340
340
|
pyproject_toml = load_toml(current_path / "pyproject.toml")
|
|
341
341
|
if "datamodel-codegen" in pyproject_toml.get("tool", {}):
|
|
342
|
-
|
|
342
|
+
pyproject_config = pyproject_toml["tool"]["datamodel-codegen"]
|
|
343
|
+
# Convert options from kebap- to snake-case
|
|
344
|
+
pyproject_config = {k.replace("-", "_"): v for k, v in pyproject_config.items()}
|
|
345
|
+
# Replace US-american spelling if present (ignore if british spelling is present)
|
|
346
|
+
if "capitalize_enum_members" in pyproject_config and "capitalise_enum_members" not in pyproject_config:
|
|
347
|
+
pyproject_config["capitalise_enum_members"] = pyproject_config.pop("capitalize_enum_members")
|
|
348
|
+
return pyproject_config
|
|
343
349
|
|
|
344
350
|
if (current_path / ".git").exists():
|
|
345
351
|
# Stop early if we see a git repository root.
|
|
346
|
-
return
|
|
352
|
+
return {}
|
|
347
353
|
|
|
348
354
|
current_path = current_path.parent
|
|
349
|
-
return
|
|
355
|
+
return {}
|
|
350
356
|
|
|
351
357
|
|
|
352
358
|
def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912, PLR0915
|
|
@@ -367,13 +373,9 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
|
|
|
367
373
|
sys.exit(0)
|
|
368
374
|
|
|
369
375
|
pyproject_config = _get_pyproject_toml_config(Path.cwd())
|
|
370
|
-
if pyproject_config is not None:
|
|
371
|
-
pyproject_toml = {k.replace("-", "_"): v for k, v in pyproject_config.items()}
|
|
372
|
-
else:
|
|
373
|
-
pyproject_toml = {}
|
|
374
376
|
|
|
375
377
|
try:
|
|
376
|
-
config = Config.parse_obj(
|
|
378
|
+
config = Config.parse_obj(pyproject_config)
|
|
377
379
|
config.merge_args(namespace)
|
|
378
380
|
except Error as e:
|
|
379
381
|
print(e.message, file=sys.stderr) # noqa: T201
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
{% if base_class != "BaseModel" and "," not in base_class and not fields and not config -%}
|
|
2
|
+
|
|
3
|
+
{# if this is just going to be `class Foo(Bar): pass`, then might as well just make Foo
|
|
4
|
+
an alias for Bar: every pydantic model class consumes considerable memory. #}
|
|
5
|
+
{{ class_name }} = {{ base_class }}
|
|
6
|
+
|
|
7
|
+
{% else -%}
|
|
8
|
+
|
|
1
9
|
{% for decorator in decorators -%}
|
|
2
10
|
{{ decorator }}
|
|
3
11
|
{% endfor -%}
|
|
@@ -37,3 +45,5 @@ class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comme
|
|
|
37
45
|
{{ method }}
|
|
38
46
|
{%- endfor -%}
|
|
39
47
|
{%- endfor -%}
|
|
48
|
+
|
|
49
|
+
{%- endif %}
|
|
@@ -949,10 +949,14 @@ class Parser(ABC):
|
|
|
949
949
|
model_field.constraints = ConstraintsBase.merge_constraints(
|
|
950
950
|
root_type_field.constraints, model_field.constraints
|
|
951
951
|
)
|
|
952
|
-
if
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
952
|
+
if (
|
|
953
|
+
isinstance(
|
|
954
|
+
root_type_field,
|
|
955
|
+
pydantic_model.DataModelField,
|
|
956
|
+
)
|
|
957
|
+
and not model_field.extras.get("discriminator")
|
|
958
|
+
and not any(t.is_list for t in model_field.data_type.data_types)
|
|
959
|
+
):
|
|
956
960
|
discriminator = root_type_field.extras.get("discriminator")
|
|
957
961
|
if discriminator:
|
|
958
962
|
model_field.extras["discriminator"] = discriminator
|
|
@@ -1148,7 +1152,7 @@ class Parser(ABC):
|
|
|
1148
1152
|
else:
|
|
1149
1153
|
r.append(item)
|
|
1150
1154
|
|
|
1151
|
-
r = r[:-2]
|
|
1155
|
+
r = [*r[:-2], f"{r[-2]}.{r[-1]}"]
|
|
1152
1156
|
return tuple(r)
|
|
1153
1157
|
|
|
1154
1158
|
results = {process(k): v for k, v in results.items()}
|
|
@@ -1184,6 +1188,24 @@ class Parser(ABC):
|
|
|
1184
1188
|
class_name=True,
|
|
1185
1189
|
).name
|
|
1186
1190
|
|
|
1191
|
+
def __alias_shadowed_imports( # noqa: PLR6301
|
|
1192
|
+
self,
|
|
1193
|
+
models: list[DataModel],
|
|
1194
|
+
all_model_field_names: set[str],
|
|
1195
|
+
) -> None:
|
|
1196
|
+
for model in models:
|
|
1197
|
+
for model_field in model.fields:
|
|
1198
|
+
if model_field.data_type.type in all_model_field_names:
|
|
1199
|
+
alias = model_field.data_type.type + "_aliased"
|
|
1200
|
+
model_field.data_type.type = alias
|
|
1201
|
+
if model_field.data_type.import_: # pragma: no cover
|
|
1202
|
+
model_field.data_type.import_ = Import(
|
|
1203
|
+
from_=model_field.data_type.import_.from_,
|
|
1204
|
+
import_=model_field.data_type.import_.import_,
|
|
1205
|
+
alias=alias,
|
|
1206
|
+
reference_path=model_field.data_type.import_.reference_path,
|
|
1207
|
+
)
|
|
1208
|
+
|
|
1187
1209
|
def parse( # noqa: PLR0912, PLR0914, PLR0915
|
|
1188
1210
|
self,
|
|
1189
1211
|
with_import: bool | None = True, # noqa: FBT001, FBT002
|
|
@@ -1278,6 +1300,7 @@ class Parser(ABC):
|
|
|
1278
1300
|
all_module_fields = {field.name for model in models for field in model.fields if field.name is not None}
|
|
1279
1301
|
scoped_model_resolver = ModelResolver(exclude_names=all_module_fields)
|
|
1280
1302
|
|
|
1303
|
+
self.__alias_shadowed_imports(models, all_module_fields)
|
|
1281
1304
|
self.__override_required_field(models)
|
|
1282
1305
|
self.__replace_unique_list_to_set(models)
|
|
1283
1306
|
self.__change_from_import(models, imports, scoped_model_resolver, init)
|
{datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.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.29.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
|
|
@@ -21,7 +21,7 @@ Requires-Python: >=3.9
|
|
|
21
21
|
Requires-Dist: argcomplete<4,>=2.10.1
|
|
22
22
|
Requires-Dist: black>=19.10b0
|
|
23
23
|
Requires-Dist: genson<2,>=1.2.1
|
|
24
|
-
Requires-Dist: inflect<
|
|
24
|
+
Requires-Dist: inflect<8,>=4.1
|
|
25
25
|
Requires-Dist: isort<7,>=4.3.21
|
|
26
26
|
Requires-Dist: jinja2<4,>=2.10.1
|
|
27
27
|
Requires-Dist: packaging
|
{datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/RECORD
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
datamodel_code_generator/__init__.py,sha256=
|
|
2
|
-
datamodel_code_generator/__main__.py,sha256=
|
|
1
|
+
datamodel_code_generator/__init__.py,sha256=UlQ_-1Gvin3ODyoli29GCYwUw0iYF8AeflKooYxusL8,20354
|
|
2
|
+
datamodel_code_generator/__main__.py,sha256=Jd_WEPtOWj38WitNuNAGGJjMChKTW6aZkSXz0LOd94w,22507
|
|
3
3
|
datamodel_code_generator/arguments.py,sha256=LQyCC7tsDdy7ie7nbQVVW_79usVumX8O5pd99ZZ51ds,16466
|
|
4
4
|
datamodel_code_generator/format.py,sha256=zvX0KH1uWwGnTYoVM4KhAuKZn5erjkH5eyi4t3leirw,8962
|
|
5
5
|
datamodel_code_generator/http.py,sha256=LE94GC7I9D8lWIg_YAGWedfy0XNxOXTmiYKuNMTwouo,887
|
|
@@ -44,16 +44,16 @@ datamodel_code_generator/model/template/pydantic/BaseModel.jinja2,sha256=sYZa-47
|
|
|
44
44
|
datamodel_code_generator/model/template/pydantic/BaseModel_root.jinja2,sha256=WDdTXYNTrkIw-B4OvPVxOaETTknLs0zdNuq_iDQ2Bcw,1000
|
|
45
45
|
datamodel_code_generator/model/template/pydantic/Config.jinja2,sha256=Ik028qdqQhDfEP207TCbwVv2b5Do1-nRNDPKzBHKzwM,135
|
|
46
46
|
datamodel_code_generator/model/template/pydantic/dataclass.jinja2,sha256=hM4OZTVhtOokqlPNSdh5drhBXfQLPvbyO88jipSPr5Y,629
|
|
47
|
-
datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=
|
|
47
|
+
datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2,sha256=i1Wg9W20c4UGUkGJUf2rjuRNO52zLbktndfYupgJA78,1442
|
|
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=
|
|
51
|
+
datamodel_code_generator/parser/base.py,sha256=O6KN8fbODI0ED9clVRQmxdtnliSTP6IBlqJXEzDzuIQ,61740
|
|
52
52
|
datamodel_code_generator/parser/graphql.py,sha256=ODbkMp42fYh8kH81KNeAffcFTmJb6_hgMyCsLUmdpMo,22585
|
|
53
53
|
datamodel_code_generator/parser/jsonschema.py,sha256=J5Ec5Vf4LGjCRWPraBmpTkepq-tN0ri5MKB9bUSDdFc,69912
|
|
54
54
|
datamodel_code_generator/parser/openapi.py,sha256=MfHSVfwq7qx_YEOiNel-ABbwISdH-kp87Q09WeNr_5w,27180
|
|
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.
|
|
55
|
+
datamodel_code_generator-0.29.0.dist-info/METADATA,sha256=x-MFb_RFCzqFGvaBJENYUN0mYe2Pz6MKoynwHUActmk,25189
|
|
56
|
+
datamodel_code_generator-0.29.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
57
|
+
datamodel_code_generator-0.29.0.dist-info/entry_points.txt,sha256=cJVcHiEViQMANaoM5C1xR5hzmyCqH6hHHMpV8W00in8,77
|
|
58
|
+
datamodel_code_generator-0.29.0.dist-info/licenses/LICENSE,sha256=K54Lwc6_jduycsy8oFFjQEeSSuEiqvVIjCGIXOMnuTQ,1068
|
|
59
|
+
datamodel_code_generator-0.29.0.dist-info/RECORD,,
|
{datamodel_code_generator-0.28.5.dist-info → datamodel_code_generator-0.29.0.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|