Skip to content

Commit f2859a6

Browse files
authored
Add deprecation warning for default output-model-type (#2910)
1 parent dcc5567 commit f2859a6

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ skip = '.git,*.lock,tests,docs/cli-reference,CHANGELOG.md,docs/changelog.md'
213213
filterwarnings = [
214214
"error",
215215
"ignore:^.*Pydantic v1 runtime support is deprecated.*:DeprecationWarning",
216+
"ignore:^.*No --output-model-type specified.*:DeprecationWarning",
216217
"ignore:^.*`--validation` option is deprecated.*",
217218
"ignore:^.*--parent-scoped-naming is deprecated.*",
218219
"ignore:^.*Field name `name` is duplicated on Pet.*",

src/datamodel_code_generator/__main__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,22 @@ def main(args: Sequence[str] | None = None) -> Exit: # noqa: PLR0911, PLR0912,
11931193
if config.disable_warnings:
11941194
warnings.simplefilter("ignore")
11951195

1196+
if (
1197+
namespace.output_model_type is None
1198+
and pyproject_config.get("output_model_type") is None
1199+
and config.output_model_type == DataModelType.PydanticBaseModel
1200+
):
1201+
warnings.warn(
1202+
"No --output-model-type specified. "
1203+
"The current default (pydantic.BaseModel, Pydantic v1) is deprecated "
1204+
"and will be removed in a future version. "
1205+
"Please explicitly specify --output-model-type. "
1206+
"Example: --output-model-type pydantic_v2.BaseModel. "
1207+
"See https://github.com/koxudaxi/datamodel-code-generator/issues/2466",
1208+
DeprecationWarning,
1209+
stacklevel=1,
1210+
)
1211+
11961212
if not is_pydantic_v2():
11971213
warnings.warn(
11981214
"Pydantic v1 runtime support is deprecated and will be removed in a future version. "

0 commit comments

Comments
 (0)