Skip to content

Commit dd6ff12

Browse files
docs: update CLI reference documentation
🤖 Generated by GitHub Actions
1 parent 4485283 commit dd6ff12

3 files changed

Lines changed: 119 additions & 2 deletions

File tree

docs/cli-reference/general-options.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| [`--http-ignore-tls`](#http-ignore-tls) | Disable TLS certificate verification for HTTPS requests. |
1515
| [`--http-query-parameters`](#http-query-parameters) | Add query parameters to HTTP requests for remote schemas. |
1616
| [`--ignore-pyproject`](#ignore-pyproject) | Ignore pyproject.toml configuration file. |
17+
| [`--module-split-mode`](#module-split-mode) | Split generated models into separate files, one per model cl... |
1718
| [`--shared-module-name`](#shared-module-name) | Customize the name of the shared module for deduplicated mod... |
1819

1920
---
@@ -1670,6 +1671,116 @@ testing without project configuration.
16701671

16711672
---
16721673

1674+
## `--module-split-mode` {#module-split-mode}
1675+
1676+
Split generated models into separate files, one per model class.
1677+
1678+
The `--module-split-mode=single` flag generates each model class in its own file,
1679+
named after the class in snake_case. Use with `--all-exports-scope=recursive` to
1680+
create an __init__.py that re-exports all models for convenient imports.
1681+
1682+
**Related:** [`--all-exports-scope`](general-options.md#all-exports-scope)
1683+
1684+
!!! tip "Usage"
1685+
1686+
```bash
1687+
datamodel-codegen --input schema.json --module-split-mode single --all-exports-scope recursive # (1)!
1688+
```
1689+
1690+
1. :material-arrow-left: `--module-split-mode` - the option documented here
1691+
1692+
??? example "Input Schema"
1693+
1694+
```json
1695+
{
1696+
"$schema": "http://json-schema.org/draft-07/schema#",
1697+
"definitions": {
1698+
"User": {
1699+
"type": "object",
1700+
"properties": {
1701+
"id": {"type": "integer"},
1702+
"name": {"type": "string"}
1703+
}
1704+
},
1705+
"Order": {
1706+
"type": "object",
1707+
"properties": {
1708+
"id": {"type": "integer"},
1709+
"user": {"$ref": "#/definitions/User"}
1710+
}
1711+
}
1712+
}
1713+
}
1714+
```
1715+
1716+
??? example "Output"
1717+
1718+
```python
1719+
# __init__.py
1720+
# generated by datamodel-codegen:
1721+
# filename: input.json
1722+
1723+
from __future__ import annotations
1724+
1725+
from .model import Model
1726+
from .order import Order
1727+
from .user import User
1728+
1729+
__all__ = [
1730+
"Model",
1731+
"Order",
1732+
"User",
1733+
]
1734+
1735+
# model.py
1736+
# generated by datamodel-codegen:
1737+
# filename: input.json
1738+
1739+
from __future__ import annotations
1740+
1741+
from typing import Any
1742+
1743+
from pydantic import BaseModel
1744+
1745+
1746+
class Model(BaseModel):
1747+
__root__: Any
1748+
1749+
# order.py
1750+
# generated by datamodel-codegen:
1751+
# filename: input.json
1752+
1753+
from __future__ import annotations
1754+
1755+
from typing import Optional
1756+
1757+
from pydantic import BaseModel
1758+
1759+
from . import user as user_1
1760+
1761+
1762+
class Order(BaseModel):
1763+
id: Optional[int] = None
1764+
user: Optional[user_1.User] = None
1765+
1766+
# user.py
1767+
# generated by datamodel-codegen:
1768+
# filename: input.json
1769+
1770+
from __future__ import annotations
1771+
1772+
from typing import Optional
1773+
1774+
from pydantic import BaseModel
1775+
1776+
1777+
class User(BaseModel):
1778+
id: Optional[int] = None
1779+
name: Optional[str] = None
1780+
```
1781+
1782+
---
1783+
16731784
## `--shared-module-name` {#shared-module-name}
16741785

16751786
Customize the name of the shared module for deduplicated models.

docs/cli-reference/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ This documentation is auto-generated from test cases.
1414
| 🏗️ [Model Customization](model-customization.md) | 26 | Model generation behavior |
1515
| 🎨 [Template Customization](template-customization.md) | 15 | Output formatting and custom rendering |
1616
| 📘 [OpenAPI-only Options](openapi-only-options.md) | 5 | OpenAPI-specific features |
17-
| ⚙️ [General Options](general-options.md) | 11 | Utilities and meta options |
17+
| ⚙️ [General Options](general-options.md) | 12 | Utilities and meta options |
1818
| 📝 [Utility Options](utility-options.md) | 5 | Help, version, debug options |
1919

2020
## All Options
2121

22-
**Jump to:** [A](#a) · [B](#b) · [C](#c) · [D](#d) · [E](#e) · [F](#f) · [G](#g) · [H](#h) · [I](#i) · [K](#k) · [N](#n) · [O](#o) · [P](#p) · [R](#r) · [S](#s) · [T](#t) · [U](#u) · [V](#v) · [W](#w)
22+
**Jump to:** [A](#a) · [B](#b) · [C](#c) · [D](#d) · [E](#e) · [F](#f) · [G](#g) · [H](#h) · [I](#i) · [K](#k) · [M](#m) · [N](#n) · [O](#o) · [P](#p) · [R](#r) · [S](#s) · [T](#t) · [U](#u) · [V](#v) · [W](#w)
2323

2424

2525
### A {#a}
@@ -101,6 +101,10 @@ This documentation is auto-generated from test cases.
101101
- [`--keep-model-order`](model-customization.md#keep-model-order)
102102
- [`--keyword-only`](model-customization.md#keyword-only)
103103

104+
### M {#m}
105+
106+
- [`--module-split-mode`](general-options.md#module-split-mode)
107+
104108
### N {#n}
105109

106110
- [`--no-alias`](field-customization.md#no-alias)

docs/cli-reference/quick-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ datamodel-codegen [OPTIONS]
143143
| [`--http-ignore-tls`](general-options.md#http-ignore-tls) | Disable TLS certificate verification for HTTPS requests. |
144144
| [`--http-query-parameters`](general-options.md#http-query-parameters) | Add query parameters to HTTP requests for remote schemas. |
145145
| [`--ignore-pyproject`](general-options.md#ignore-pyproject) | Ignore pyproject.toml configuration file. |
146+
| [`--module-split-mode`](general-options.md#module-split-mode) | Split generated models into separate files, one per model class. |
146147
| [`--shared-module-name`](general-options.md#shared-module-name) | Customize the name of the shared module for deduplicated models. |
147148

148149
### 📝 Utility Options
@@ -210,6 +211,7 @@ All options sorted alphabetically:
210211
- [`--input-file-type`](base-options.md#input-file-type) - Specify the input file type for code generation.
211212
- [`--keep-model-order`](model-customization.md#keep-model-order) - Keep model definition order as specified in schema.
212213
- [`--keyword-only`](model-customization.md#keyword-only) - Generate dataclasses with keyword-only fields (Python 3.10+)...
214+
- [`--module-split-mode`](general-options.md#module-split-mode) - Split generated models into separate files, one per model cl...
213215
- [`--no-alias`](field-customization.md#no-alias) - Disable Field alias generation for non-Python-safe property ...
214216
- [`--no-color`](utility-options.md#no-color) - Disable colorized output
215217
- [`--no-use-specialized-enum`](typing-customization.md#no-use-specialized-enum) - Disable specialized Enum classes for Python 3.11+ code gener...

0 commit comments

Comments
 (0)