Skip to content

Commit 850d006

Browse files
committed
feat: remove pydantic v1 output support
1 parent 03200be commit 850d006

362 files changed

Lines changed: 2667 additions & 4353 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/datamodel_code_generator/__main__.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ def __getitem__(self, item: str) -> Any: # pragma: no cover
151151
"""Get item by key."""
152152
return self.get(item) # ty: ignore
153153

154-
@classmethod
155-
def parse_obj(cls, obj: Any) -> Self:
156-
"""Parse object into Config model."""
157-
return cls.model_validate(obj)
158-
159154
@classmethod
160155
def get_fields(cls) -> dict[str, Any]:
161156
"""Get model fields."""
@@ -396,17 +391,15 @@ def validate_all_exports_collision_strategy(self: Self) -> Self: # ty: ignore
396391
raise Error(self.__validate_all_exports_collision_strategy_err)
397392
return self
398393

399-
from pydantic import field_validator as _field_validator # noqa: PLC0415
400-
401-
@_field_validator("input_model", mode="before")
394+
@field_validator("input_model", mode="before")
402395
@classmethod
403396
def coerce_input_model_to_list(cls, v: str | list[str] | None) -> list[str] | None: # ty: ignore
404397
"""Convert string input_model to list for backwards compatibility."""
405398
if isinstance(v, str):
406399
return [v]
407400
return v
408401

409-
@_field_validator("class_name_affix_scope", mode="before")
402+
@field_validator("class_name_affix_scope", mode="before")
410403
@classmethod
411404
def validate_class_name_affix_scope(cls, v: str | ClassNameAffixScope | None) -> ClassNameAffixScope: # ty: ignore
412405
"""Convert string to ClassNameAffixScope enum."""
@@ -564,7 +557,7 @@ def merge_args(self, args: Namespace) -> None:
564557
if set_args.get("use_annotated"):
565558
set_args["field_constraints"] = True
566559

567-
parsed_args = Config.parse_obj(set_args)
560+
parsed_args = Config.model_validate(set_args)
568561
for field_name in set_args:
569562
setattr(self, field_name, getattr(parsed_args, field_name))
570563

@@ -1063,7 +1056,7 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
10631056
return Exit.OK
10641057

10651058
try:
1066-
config = Config.parse_obj(pyproject_config)
1059+
config = Config.model_validate(pyproject_config)
10671060
config.merge_args(namespace)
10681061
except Error as e:
10691062
print(e.message, file=sys.stderr) # noqa: T201

src/datamodel_code_generator/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def start_section(self, heading: str | None) -> None:
831831
)
832832
field_options.add_argument(
833833
"--use-frozen-field",
834-
help="Use Field(frozen=True) for readOnly fields (Pydantic v2) or Field(allow_mutation=False) (Pydantic v1)",
834+
help="Use Field(frozen=True) for readOnly fields (Pydantic v2).",
835835
action="store_true",
836836
default=None,
837837
)

src/datamodel_code_generator/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
PythonVersion,
4040
PythonVersionMin,
4141
)
42-
from datamodel_code_generator.model import pydantic as pydantic_model
42+
from datamodel_code_generator.model import pydantic_v2
4343
from datamodel_code_generator.model.base import ( # noqa: TC001 - used by Pydantic at runtime
4444
DataModel,
4545
DataModelFieldBase,
@@ -205,10 +205,10 @@ class ParserConfig(BaseModel):
205205

206206
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
207207

208-
data_model_type: type[DataModel] = pydantic_model.BaseModel
209-
data_model_root_type: type[DataModel] = pydantic_model.CustomRootType
210-
data_type_manager_type: type[DataTypeManager] = pydantic_model.DataTypeManager
211-
data_model_field_type: type[DataModelFieldBase] = pydantic_model.DataModelField
208+
data_model_type: type[DataModel] = pydantic_v2.BaseModel
209+
data_model_root_type: type[DataModel] = pydantic_v2.RootModel
210+
data_type_manager_type: type[DataTypeManager] = pydantic_v2.DataTypeManager
211+
data_model_field_type: type[DataModelFieldBase] = pydantic_v2.DataModelField
212212
base_class: str | None = None
213213
base_class_map: dict[str, str | list[str]] | None = None
214214
additional_imports: list[str] | None = None

src/datamodel_code_generator/enums.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class InputFileType(Enum):
4848
class DataModelType(Enum):
4949
"""Supported output data model types."""
5050

51-
PydanticBaseModel = "pydantic.BaseModel"
5251
PydanticV2BaseModel = "pydantic_v2.BaseModel"
5352
PydanticV2Dataclass = "pydantic_v2.dataclass"
5453
DataclassesDataclass = "dataclasses.dataclass"

src/datamodel_code_generator/input_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ def _get_output_family(output_model_type: DataModelType) -> str:
514514
from datamodel_code_generator import DataModelType # noqa: PLC0415
515515

516516
pydantic_types = {
517-
DataModelType.PydanticBaseModel,
518517
DataModelType.PydanticV2BaseModel,
519518
DataModelType.PydanticV2Dataclass,
520519
}

src/datamodel_code_generator/model/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def get_data_model_types( # noqa: PLR0912
4747
from . import ( # noqa: PLC0415
4848
dataclass,
4949
msgspec,
50-
pydantic,
5150
pydantic_v2,
5251
scalar,
5352
type_alias,
@@ -75,16 +74,6 @@ def get_data_model_types( # noqa: PLR0912
7574
scalar_class = scalar.DataTypeScalar
7675
union_class = union.DataTypeUnion
7776

78-
if data_model_type == DataModelType.PydanticBaseModel:
79-
return DataModelSet(
80-
data_model=pydantic.BaseModel,
81-
root_model=type_alias_class if use_type_alias else pydantic.CustomRootType,
82-
field_model=pydantic.DataModelField,
83-
data_type_manager=pydantic.DataTypeManager,
84-
dump_resolve_reference_action=pydantic.dump_resolve_reference_action,
85-
scalar_model=scalar_class,
86-
union_model=union_class,
87-
)
8877
if data_model_type == DataModelType.PydanticV2BaseModel:
8978
if use_type_alias:
9079
root_model_class: type[DataModel] = type_alias_class

src/datamodel_code_generator/model/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(self, **data: Any) -> None:
186186
self.data_type.parent = self
187187
self.process_const()
188188

189-
def process_const(self) -> None:
189+
def process_const(self) -> None: # pragma: no cover
190190
"""Process const values by setting them as defaults."""
191191
if "const" not in self.extras:
192192
return

src/datamodel_code_generator/model/pydantic/__init__.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/datamodel_code_generator/model/pydantic/base_model.py

Lines changed: 0 additions & 137 deletions
This file was deleted.

src/datamodel_code_generator/model/pydantic/custom_root_type.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)