Skip to content

Commit d4ea4ce

Browse files
Add standard preset (#3422)
* Add standard preset * style: auto-fix by pre-commit.ci * Update skill CLI reference * Address preset review findings * Fix preset tests on older black * Cover preset metadata helpers * Cover preset override branches * Address preset docs review * Address preset review comments * Preserve related CLI doc links * Use typed config for presets * Derive preset config from groups * Lazy load preset resolver * Handle preset tests with older black * Cover unknown preset pyproject errors * Inline typed preset config * Return explicit preset updates * Address preset review feedback * Avoid mixed preset render returns * Initialize preset render output * Use typed preset config updates * Tighten preset config typing * Use BaseGenerateConfig for preset config * Use literal for single enum preset * Fix preset literal test target * Add strict nullable to standard preset * Add practical preset * Document preset workflows * Refine preset quick start * Update preset date * Add target-specific presets * Cover preset enum config values * Refine preset options * Update preset formatter fixtures * Infer target from preset * style: auto-fix by pre-commit.ci * Refine preset target validation * Remove target version from preset examples * Clarify expanded preset examples * Improve preset docs navigation * Simplify preset quick start * Reorder README sections * Clarify Python baseline in quick start * Refresh preset quick start examples * Refine preset quick start docs * Type preset names as literals * Strengthen preset name typing * Add preset to generate API * Generate typed preset config dict * Share preset config resolution * Remove duplicate preset resolvers * Cover preset config branches --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5d237ac commit d4ea4ce

84 files changed

Lines changed: 6314 additions & 200 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.

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/scripts/update_command_help_on_markdown.py @koxudaxi
88
/scripts/build_cli_docs.py @koxudaxi
99
/scripts/build_prompt_data.py @koxudaxi
10+
/scripts/build_preset_docs.py @koxudaxi
1011
/scripts/build_schema_docs.py @koxudaxi
1112
/scripts/build_llms_txt.py @koxudaxi
1213
/scripts/update_docs_version.py @koxudaxi

.github/workflows/cli-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
env:
3636
UV_PYTHON_PREFERENCE: "only-managed"
3737
- name: Collect CLI doc metadata
38-
run: .tox/cli-docs/bin/pytest --collect-cli-docs -p no:xdist -q
38+
run: .tox/cli-docs/bin/pytest tests --collect-cli-docs -p no:xdist -q
3939
- name: Build CLI docs
4040
run: .tox/cli-docs/bin/python scripts/build_cli_docs.py
4141
- name: Build prompt data

.github/workflows/generated-docs-sync.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ on:
77
paths:
88
- 'src/datamodel_code_generator/**'
99
- 'tests/main/**'
10+
- 'tests/data/jsonschema/tutorial_pet.json'
1011
- 'tests/test_main_kr.py'
1112
- 'scripts/build_cli_docs.py'
1213
- 'scripts/build_prompt_data.py'
14+
- 'scripts/build_preset_docs.py'
1315
- 'scripts/build_schema_docs.py'
1416
- 'scripts/build_conformance_docs.py'
1517
- 'scripts/build_llms_txt.py'
@@ -60,6 +62,7 @@ jobs:
6062
generated_paths=(
6163
README.md
6264
docs/index.md
65+
docs/presets.md
6366
docs/conformance.md
6467
docs/cli-reference/
6568
docs/llms.txt

.github/workflows/llms-txt.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ on:
66
paths:
77
- 'src/datamodel_code_generator/**'
88
- 'tests/main/**'
9+
- 'tests/data/jsonschema/tutorial_pet.json'
910
- 'tests/test_main_kr.py'
1011
- 'scripts/build_cli_docs.py'
1112
- 'scripts/build_prompt_data.py'
13+
- 'scripts/build_preset_docs.py'
1214
- 'src/datamodel_code_generator/parser/schema_version.py'
1315
- 'scripts/build_schema_docs.py'
1416
- 'docs/**/*.md'
@@ -45,19 +47,25 @@ jobs:
4547
run: tox run -vv --notest --skip-missing-interpreters false -e schema-docs
4648
env:
4749
UV_PYTHON_PREFERENCE: "only-managed"
50+
- name: Setup preset docs environment
51+
run: tox run -vv --notest --skip-missing-interpreters false -e preset-docs
52+
env:
53+
UV_PYTHON_PREFERENCE: "only-managed"
4854
- name: Setup llms.txt environment
4955
run: tox run -vv --notest --skip-missing-interpreters false -e llms-txt
5056
env:
5157
UV_PYTHON_PREFERENCE: "only-managed"
5258
- name: Update README
5359
run: .tox/readme/bin/python scripts/update_command_help_on_markdown.py
5460
- name: Collect CLI doc metadata
55-
run: .tox/cli-docs/bin/pytest --collect-cli-docs -p no:xdist -q
61+
run: .tox/cli-docs/bin/pytest tests --collect-cli-docs -p no:xdist -q
5662
- name: Build CLI docs
5763
run: .tox/cli-docs/bin/python scripts/build_cli_docs.py
5864
- name: Build prompt data
5965
run: .tox/cli-docs/bin/python scripts/build_prompt_data.py
6066
- name: Build schema docs
6167
run: .tox/schema-docs/bin/python scripts/build_schema_docs.py
68+
- name: Build preset docs
69+
run: .tox/preset-docs/bin/python scripts/build_preset_docs.py
6270
- name: Build llms.txt
6371
run: .tox/llms-txt/bin/python scripts/build_llms_txt.py

.github/workflows/readme.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
- 'src/datamodel_code_generator/**'
88
- 'README.md'
99
- 'docs/index.md'
10+
- 'docs/presets.md'
11+
- 'scripts/build_preset_docs.py'
12+
- 'tests/data/jsonschema/tutorial_pet.json'
1013

1114
permissions:
1215
contents: read
@@ -29,5 +32,11 @@ jobs:
2932
run: tox run -vv --notest --skip-missing-interpreters false -e readme
3033
env:
3134
UV_PYTHON_PREFERENCE: "only-managed"
35+
- name: Setup preset docs environment
36+
run: tox run -vv --notest --skip-missing-interpreters false -e preset-docs
37+
env:
38+
UV_PYTHON_PREFERENCE: "only-managed"
3239
- name: Update README
3340
run: .tox/readme/bin/python scripts/update_command_help_on_markdown.py
41+
- name: Check preset docs
42+
run: .tox/preset-docs/bin/python scripts/build_preset_docs.py --check

README.md

Lines changed: 80 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,6 @@ in another Python file to a different output type.
4141

4242
---
4343

44-
## 📖 Documentation
45-
46-
**👉 [datamodel-code-generator.koxudaxi.dev](https://datamodel-code-generator.koxudaxi.dev)**
47-
48-
- 🖥️ [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) - All command-line options
49-
- 🧪 [Playground](https://datamodel-code-generator.koxudaxi.dev/playground/) - Try generation in your browser
50-
- ⚙️ [pyproject.toml](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) - Configuration file
51-
- 🔄 [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) - GitHub Actions, pre-commit hooks
52-
-[Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/) - External corpus coverage signals
53-
- 🚀 [One-liner Usage](https://datamodel-code-generator.koxudaxi.dev/oneliner/) - uvx, pipx, clipboard integration
54-
-[FAQ](https://datamodel-code-generator.koxudaxi.dev/faq/) - Common questions
55-
56-
---
57-
58-
## Coding agent skill
59-
60-
This repository includes an experimental Agent Skill that teaches compatible coding agents to run `datamodel-codegen` when generating Python models from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects.
61-
62-
See [Coding Agent Skill](docs/coding-agent-skill.md) for detailed guidance and troubleshooting.
63-
64-
Install the directory for your agent:
65-
66-
```bash
67-
# Codex, project-local
68-
mkdir -p .agents/skills
69-
cp -R skills/datamodel-code-generator .agents/skills/datamodel-code-generator
70-
71-
# Claude Code, project-local
72-
mkdir -p .claude/skills
73-
cp -R skills/datamodel-code-generator .claude/skills/datamodel-code-generator
74-
```
75-
76-
For a personal install, copy the same directory to `$HOME/.agents/skills/datamodel-code-generator/` for Codex or `~/.claude/skills/datamodel-code-generator/` for Claude Code.
77-
78-
Check your agent's current documentation for exact search paths.
79-
80-
---
81-
8244
## 📦 Installation
8345

8446
Recommended for standalone CLI use:
@@ -137,27 +99,46 @@ docker pull koxudaxi/datamodel-code-generator
13799

138100
## 🏃 Quick Start
139101

102+
<!-- BEGIN AUTO-GENERATED PRESET QUICK START -->
103+
**Command**
104+
140105
```bash
141-
datamodel-codegen --input schema.json --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output model.py
106+
datamodel-codegen \
107+
--input schema.json \
108+
--input-file-type jsonschema \
109+
--output-model-type pydantic_v2.BaseModel \
110+
--preset standard-py312-20260619 \
111+
--output model.py
142112
```
143113

114+
This quick start uses `standard-py312-20260619` as the modern Python 3.12 baseline.
115+
Preset names include the target Python version: `py312` means Python 3.12.
116+
117+
See [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) for all options. See [Presets](https://datamodel-code-generator.koxudaxi.dev/presets/),
118+
[`--preset`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#preset), [`--input-file-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/base-options/#input-file-type), and
119+
[`--output-model-type`](https://datamodel-code-generator.koxudaxi.dev/cli-reference/model-customization/#output-model-type) for this command.
120+
121+
For more schema-aware output that preserves schema-authored names, reuses models, and embeds generated
122+
documentation, use [`practical-py312-20260619`](https://datamodel-code-generator.koxudaxi.dev/presets/#practical-py312-20260619).
123+
144124
<details>
145-
<summary>📄 schema.json (input)</summary>
125+
<summary>Input (<code>schema.json</code>)</summary>
146126

147127
```json
148128
{
149129
"$schema": "http://json-schema.org/draft-07/schema#",
150130
"title": "Pet",
151131
"type": "object",
152-
"required": ["name", "species"],
132+
"required": ["name"],
153133
"properties": {
154134
"name": {
155135
"type": "string",
156136
"description": "The pet's name"
157137
},
158138
"species": {
159139
"type": "string",
160-
"enum": ["dog", "cat", "bird", "fish"]
140+
"enum": ["dog", "cat", "bird", "fish"],
141+
"default": "dog"
161142
},
162143
"age": {
163144
"type": "integer",
@@ -174,36 +155,52 @@ datamodel-codegen --input schema.json --input-file-type jsonschema --output-mode
174155

175156
</details>
176157

177-
<details>
178-
<summary>🐍 model.py (output)</summary>
158+
**Output (`model.py`)**
179159

180160
```python
181161
# generated by datamodel-codegen:
182162
# filename: schema.json
183163

184164
from __future__ import annotations
185165

186-
from enum import Enum
187-
from typing import Optional
166+
from enum import StrEnum
167+
from typing import Annotated
188168

189-
from pydantic import BaseModel, Field
169+
from pydantic import BaseModel, ConfigDict, Field
190170

191171

192-
class Species(Enum):
172+
class Species(StrEnum):
193173
dog = 'dog'
194174
cat = 'cat'
195175
bird = 'bird'
196176
fish = 'fish'
197177

198178

199179
class Pet(BaseModel):
200-
name: str = Field(..., description="The pet's name")
201-
species: Species
202-
age: Optional[int] = Field(None, description='Age in years', ge=0)
203-
vaccinated: Optional[bool] = False
180+
model_config = ConfigDict(
181+
populate_by_name=True,
182+
)
183+
name: Annotated[str, Field(description="The pet's name")]
184+
species: Species = Species.dog
185+
age: Annotated[int | None, Field(description='Age in years', ge=0)] = None
186+
vaccinated: bool = False
204187
```
188+
<!-- END AUTO-GENERATED PRESET QUICK START -->
205189

206-
</details>
190+
---
191+
192+
## 📖 Documentation
193+
194+
**👉 [datamodel-code-generator.koxudaxi.dev](https://datamodel-code-generator.koxudaxi.dev)**
195+
196+
- 🧰 [Presets](https://datamodel-code-generator.koxudaxi.dev/presets/) - Recommended option bundles for modern output
197+
- 🖥️ [CLI Reference](https://datamodel-code-generator.koxudaxi.dev/cli-reference/) - All command-line options
198+
- 🧪 [Playground](https://datamodel-code-generator.koxudaxi.dev/playground/) - Try generation in your browser
199+
- ⚙️ [pyproject.toml](https://datamodel-code-generator.koxudaxi.dev/pyproject_toml/) - Configuration file
200+
- 🔄 [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) - GitHub Actions, pre-commit hooks
201+
-[Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/) - External corpus coverage signals
202+
- 🚀 [One-liner Usage](https://datamodel-code-generator.koxudaxi.dev/oneliner/) - uvx, pipx, clipboard integration
203+
-[FAQ](https://datamodel-code-generator.koxudaxi.dev/faq/) - Common questions
207204

208205
---
209206

@@ -221,12 +218,6 @@ class Pet(BaseModel):
221218
- Python types (Pydantic, dataclass, TypedDict) via `--input-model`
222219
- Python dictionary
223220

224-
## ✅ Conformance Signals
225-
226-
CI exercises datamodel-code-generator against pinned external corpora for XML Schema, JSON Schema, AsyncAPI, Apache
227-
Avro, and Protocol Buffers. See the [Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/)
228-
for the generated summary of runner scripts, tox environments, CI jobs, expected corpus counts, and upstream sources.
229-
230221
## 📤 Supported Output
231222

232223
- [pydantic v2](https://docs.pydantic.dev/) BaseModel
@@ -235,6 +226,12 @@ for the generated summary of runner scripts, tox environments, CI jobs, expected
235226
- [TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
236227
- [msgspec](https://github.com/jcrist/msgspec) Struct
237228

229+
## ✅ Conformance Signals
230+
231+
CI exercises datamodel-code-generator against pinned external corpora for XML Schema, JSON Schema, AsyncAPI, Apache
232+
Avro, and Protocol Buffers. See the [Conformance Dashboard](https://datamodel-code-generator.koxudaxi.dev/conformance/)
233+
for the generated summary of runner scripts, tox environments, CI jobs, expected corpus counts, and upstream sources.
234+
238235
---
239236

240237
## 🍳 Common Recipes
@@ -288,6 +285,30 @@ See [CI/CD Integration](https://datamodel-code-generator.koxudaxi.dev/ci-cd/) fo
288285
289286
---
290287
288+
## Coding agent skill
289+
290+
This repository includes an experimental Agent Skill that teaches compatible coding agents to run `datamodel-codegen` when generating Python models from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects.
291+
292+
See [Coding Agent Skill](docs/coding-agent-skill.md) for detailed guidance and troubleshooting.
293+
294+
Install the directory for your agent:
295+
296+
```bash
297+
# Codex, project-local
298+
mkdir -p .agents/skills
299+
cp -R skills/datamodel-code-generator .agents/skills/datamodel-code-generator
300+
301+
# Claude Code, project-local
302+
mkdir -p .claude/skills
303+
cp -R skills/datamodel-code-generator .claude/skills/datamodel-code-generator
304+
```
305+
306+
For a personal install, copy the same directory to `$HOME/.agents/skills/datamodel-code-generator/` for Codex or `~/.claude/skills/datamodel-code-generator/` for Claude Code.
307+
308+
Check your agent's current documentation for exact search paths.
309+
310+
---
311+
291312
## 💖 Sponsors
292313

293314
<table>

0 commit comments

Comments
 (0)