Skip to content

Commit e12cd96

Browse files
authored
Add deprecation warning and explicit --output-model-type to docs (#2911)
* Add deprecation warning and explicit --output-model-type to docs * Add note explaining --output-model-type recommendation
1 parent f2859a6 commit e12cd96

6 files changed

Lines changed: 63 additions & 10 deletions

File tree

docs/aliases.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ The `--aliases` option allows you to rename fields in the generated models. This
77
## 🚀 Basic Usage
88

99
```bash
10-
datamodel-codegen --input schema.json --output model.py --aliases aliases.json
10+
datamodel-codegen \
11+
--input schema.json \
12+
--output-model-type pydantic_v2.BaseModel \
13+
--output model.py \
14+
--aliases aliases.json
1115
```
1216

1317
## 📋 Alias File Format

docs/formatting.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ Generated code is automatically formatted using code formatters. By default, `bl
1515
**Library users**: Explicitly pass `formatters=[Formatter.BLACK, Formatter.ISORT]` to suppress this warning.
1616

1717
```bash
18-
datamodel-codegen --input schema.yaml --output model.py
18+
datamodel-codegen \
19+
--input schema.yaml \
20+
--output-model-type pydantic_v2.BaseModel \
21+
--output model.py
1922
```
2023

2124
This runs the following formatters in order:
@@ -44,10 +47,18 @@ This runs the following formatters in order:
4447

4548
```bash
4649
# Use ruff for both linting and formatting
47-
datamodel-codegen --formatters ruff-check ruff-format --input schema.yaml --output model.py
50+
datamodel-codegen \
51+
--formatters ruff-check ruff-format \
52+
--input schema.yaml \
53+
--output-model-type pydantic_v2.BaseModel \
54+
--output model.py
4855

4956
# Use ruff-format as a black replacement
50-
datamodel-codegen --formatters isort ruff-format --input schema.yaml --output model.py
57+
datamodel-codegen \
58+
--formatters isort ruff-format \
59+
--input schema.yaml \
60+
--output-model-type pydantic_v2.BaseModel \
61+
--output model.py
5162
```
5263

5364
### 🚫 Disable formatting
@@ -91,7 +102,11 @@ quote-style = "single"
91102
By default, string quote style is determined by your formatter configuration. To force double quotes regardless of configuration:
92103

93104
```bash
94-
datamodel-codegen --use-double-quotes --input schema.yaml --output model.py
105+
datamodel-codegen \
106+
--use-double-quotes \
107+
--input schema.yaml \
108+
--output-model-type pydantic_v2.BaseModel \
109+
--output model.py
95110
```
96111

97112
This overrides `skip_string_normalization` in black config.

docs/graphql.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ Generate Pydantic models from GraphQL schema definitions.
55
## 🚀 Quick Start
66

77
```bash
8-
datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py
8+
datamodel-codegen \
9+
--input schema.graphql \
10+
--input-file-type graphql \
11+
--output-model-type pydantic_v2.BaseModel \
12+
--output model.py
913
```
1014

15+
!!! tip "Why `--output-model-type`?"
16+
Starting from version 0.53.0, explicitly specifying `--output-model-type` is recommended.
17+
See [Omitting --output-model-type is deprecated](index.md#omitting---output-model-type-is-deprecated) for details.
18+
1119
!!! note "📦 Installation"
1220
GraphQL support requires the `graphql` extra:
1321
```bash
@@ -148,7 +156,12 @@ print(books)
148156
## 🎨 Custom Scalar Types
149157

150158
```bash
151-
datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py --extra-template-data data.json
159+
datamodel-codegen \
160+
--input schema.graphql \
161+
--input-file-type graphql \
162+
--output-model-type pydantic_v2.BaseModel \
163+
--extra-template-data data.json \
164+
--output model.py
152165
```
153166

154167
**schema.graphql**
@@ -215,7 +228,12 @@ as GraphQL servers typically don't expect this field in input data.
215228
Use the `--graphql-no-typename` option to exclude this field:
216229

217230
```bash
218-
datamodel-codegen --input schema.graphql --input-file-type graphql --output model.py --graphql-no-typename
231+
datamodel-codegen \
232+
--input schema.graphql \
233+
--input-file-type graphql \
234+
--output-model-type pydantic_v2.BaseModel \
235+
--graphql-no-typename \
236+
--output model.py
219237
```
220238

221239
**Before (default):**

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363

6464
---
6565

66+
!!! warning "Omitting --output-model-type is deprecated"
67+
Starting from version 0.53.0, omitting `--output-model-type` is deprecated.
68+
The implicit default `pydantic.BaseModel` (Pydantic v1) will be removed in a future version.
69+
70+
We recommend using `--output-model-type pydantic_v2.BaseModel` for new projects.
71+
72+
---
73+
6674
## 🏃 Quick Start
6775

6876
### 1️⃣ Create a schema file

docs/jsondata.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Generate Pydantic models directly from JSON data. Under the hood, the generator
55
## 🚀 Quick Start
66

77
```bash
8-
datamodel-codegen --input pets.json --input-file-type json --output model.py
8+
datamodel-codegen \
9+
--input pets.json \
10+
--input-file-type json \
11+
--output-model-type pydantic_v2.BaseModel \
12+
--output model.py
913
```
1014

1115
## 📝 Example

docs/jsonschema.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Generate Pydantic models from JSON Schema definitions. See [Supported Data Types
55
## 🚀 Quick Start
66

77
```bash
8-
datamodel-codegen --input person.json --input-file-type jsonschema --output model.py
8+
datamodel-codegen \
9+
--input person.json \
10+
--input-file-type jsonschema \
11+
--output-model-type pydantic_v2.BaseModel \
12+
--output model.py
913
```
1014

1115
## 📝 Example

0 commit comments

Comments
 (0)