From eb350281c9eb2ec909c2be4c731ae9737211846f Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Sat, 3 Jan 2026 05:55:07 +0000 Subject: [PATCH 1/2] Add deprecation warning and explicit --output-model-type to docs --- docs/aliases.md | 6 +++++- docs/formatting.md | 23 +++++++++++++++++++---- docs/graphql.md | 20 +++++++++++++++++--- docs/index.md | 8 ++++++++ docs/jsondata.md | 6 +++++- docs/jsonschema.md | 6 +++++- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/docs/aliases.md b/docs/aliases.md index 0904708c0..742331be9 100644 --- a/docs/aliases.md +++ b/docs/aliases.md @@ -7,7 +7,11 @@ The `--aliases` option allows you to rename fields in the generated models. This ## 🚀 Basic Usage ```bash -datamodel-codegen --input schema.json --output model.py --aliases aliases.json +datamodel-codegen \ + --input schema.json \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py \ + --aliases aliases.json ``` ## 📋 Alias File Format diff --git a/docs/formatting.md b/docs/formatting.md index f04bbe8c8..37c0b7e6f 100644 --- a/docs/formatting.md +++ b/docs/formatting.md @@ -15,7 +15,10 @@ Generated code is automatically formatted using code formatters. By default, `bl **Library users**: Explicitly pass `formatters=[Formatter.BLACK, Formatter.ISORT]` to suppress this warning. ```bash -datamodel-codegen --input schema.yaml --output model.py +datamodel-codegen \ + --input schema.yaml \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` This runs the following formatters in order: @@ -44,10 +47,18 @@ This runs the following formatters in order: ```bash # Use ruff for both linting and formatting -datamodel-codegen --formatters ruff-check ruff-format --input schema.yaml --output model.py +datamodel-codegen \ + --formatters ruff-check ruff-format \ + --input schema.yaml \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py # Use ruff-format as a black replacement -datamodel-codegen --formatters isort ruff-format --input schema.yaml --output model.py +datamodel-codegen \ + --formatters isort ruff-format \ + --input schema.yaml \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` ### 🚫 Disable formatting @@ -91,7 +102,11 @@ quote-style = "single" By default, string quote style is determined by your formatter configuration. To force double quotes regardless of configuration: ```bash -datamodel-codegen --use-double-quotes --input schema.yaml --output model.py +datamodel-codegen \ + --use-double-quotes \ + --input schema.yaml \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` This overrides `skip_string_normalization` in black config. diff --git a/docs/graphql.md b/docs/graphql.md index 2e85e9002..48b168657 100644 --- a/docs/graphql.md +++ b/docs/graphql.md @@ -5,7 +5,11 @@ Generate Pydantic models from GraphQL schema definitions. ## 🚀 Quick Start ```bash -datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py +datamodel-codegen \ + --input schema.graphql \ + --input-file-type graphql \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` !!! note "📦 Installation" @@ -148,7 +152,12 @@ print(books) ## 🎨 Custom Scalar Types ```bash -datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py --extra-template-data data.json +datamodel-codegen \ + --input schema.graphql \ + --input-file-type graphql \ + --output-model-type pydantic_v2.BaseModel \ + --extra-template-data data.json \ + --output model.py ``` **schema.graphql** @@ -215,7 +224,12 @@ as GraphQL servers typically don't expect this field in input data. Use the `--graphql-no-typename` option to exclude this field: ```bash -datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py --graphql-no-typename +datamodel-codegen \ + --input schema.graphql \ + --input-file-type graphql \ + --output-model-type pydantic_v2.BaseModel \ + --graphql-no-typename \ + --output model.py ``` **Before (default):** diff --git a/docs/index.md b/docs/index.md index 481f83f3e..32327e9d3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -63,6 +63,14 @@ --- +!!! warning "Omitting --output-model-type is deprecated" + Starting from version 0.53.0, omitting `--output-model-type` is deprecated. + The implicit default `pydantic.BaseModel` (Pydantic v1) will be removed in a future version. + + We recommend using `--output-model-type pydantic_v2.BaseModel` for new projects. + +--- + ## 🏃 Quick Start ### 1️⃣ Create a schema file diff --git a/docs/jsondata.md b/docs/jsondata.md index 01c7c93c3..f606f85af 100644 --- a/docs/jsondata.md +++ b/docs/jsondata.md @@ -5,7 +5,11 @@ Generate Pydantic models directly from JSON data. Under the hood, the generator ## 🚀 Quick Start ```bash -datamodel-codegen --input pets.json --input-file-type json --output model.py +datamodel-codegen \ + --input pets.json \ + --input-file-type json \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` ## 📝 Example diff --git a/docs/jsonschema.md b/docs/jsonschema.md index 3d25ba187..0a124c92a 100644 --- a/docs/jsonschema.md +++ b/docs/jsonschema.md @@ -5,7 +5,11 @@ Generate Pydantic models from JSON Schema definitions. See [Supported Data Types ## 🚀 Quick Start ```bash -datamodel-codegen --input person.json --input-file-type jsonschema --output model.py +datamodel-codegen \ + --input person.json \ + --input-file-type jsonschema \ + --output-model-type pydantic_v2.BaseModel \ + --output model.py ``` ## 📝 Example From 61cb2c62d86932f92853e197569bec3c5978e882 Mon Sep 17 00:00:00 2001 From: Koudai Aono Date: Sat, 3 Jan 2026 07:17:56 +0000 Subject: [PATCH 2/2] Add note explaining --output-model-type recommendation --- docs/graphql.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/graphql.md b/docs/graphql.md index 48b168657..7dcc47851 100644 --- a/docs/graphql.md +++ b/docs/graphql.md @@ -12,6 +12,10 @@ datamodel-codegen \ --output model.py ``` +!!! tip "Why `--output-model-type`?" + Starting from version 0.53.0, explicitly specifying `--output-model-type` is recommended. + See [Omitting --output-model-type is deprecated](index.md#omitting---output-model-type-is-deprecated) for details. + !!! note "📦 Installation" GraphQL support requires the `graphql` extra: ```bash