Skip to content

Commit 417ac76

Browse files
committed
Merge remote-tracking branch 'origin/main' into refactor/config-class
# Conflicts: # src/datamodel_code_generator/__main__.py # tests/test_input_model.py
2 parents ead4e16 + 0f7a6c9 commit 417ac76

18 files changed

Lines changed: 1087 additions & 56 deletions

File tree

docs/cli-reference/base-options.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
| [`--input`](#input) | Specify the input schema file path. |
99
| [`--input-file-type`](#input-file-type) | Specify the input file type for code generation. |
1010
| [`--input-model`](#input-model) | Import a Python type or dict schema from a module. |
11+
| [`--input-model-ref-strategy`](#input-model-ref-strategy) | Strategy for referenced types when using --input-model. |
1112
| [`--output`](#output) | Specify the destination path for generated Python code. |
1213
| [`--url`](#url) | Fetch schema from URL with custom HTTP headers. |
1314

@@ -241,6 +242,30 @@ Use the format `module:Object` or `path/to/file.py:Object` to specify the type.
241242

242243
---
243244

245+
## `--input-model-ref-strategy` {#input-model-ref-strategy}
246+
247+
Strategy for referenced types when using --input-model.
248+
249+
The `--input-model-ref-strategy` option determines whether to regenerate or import
250+
referenced types. Use `regenerate-all` (default) to regenerate all types,
251+
`reuse-foreign` to import types from different families (like enums when generating
252+
dataclasses) while regenerating same-family types, or `reuse-all` to import all
253+
referenced types directly.
254+
255+
!!! tip "Usage"
256+
257+
```bash
258+
datamodel-codegen --input schema.json --input-model-ref-strategy reuse-foreign # (1)!
259+
```
260+
261+
1. :material-arrow-left: `--input-model-ref-strategy` - the option documented here
262+
263+
??? example "Examples"
264+
265+
**Output:**
266+
267+
---
268+
244269
## `--output` {#output}
245270

246271
Specify the destination path for generated Python code.

docs/cli-reference/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This documentation is auto-generated from test cases.
88

99
| Category | Options | Description |
1010
|----------|---------|-------------|
11-
| 📁 [Base Options](base-options.md) | 6 | Input/output configuration |
11+
| 📁 [Base Options](base-options.md) | 7 | Input/output configuration |
1212
| 🔧 [Typing Customization](typing-customization.md) | 26 | Type annotation and import behavior |
1313
| 🏷️ [Field Customization](field-customization.md) | 22 | Field naming and docstring behavior |
1414
| 🏗️ [Model Customization](model-customization.md) | 36 | Model generation behavior |
@@ -107,6 +107,7 @@ This documentation is auto-generated from test cases.
107107
- [`--input`](base-options.md#input)
108108
- [`--input-file-type`](base-options.md#input-file-type)
109109
- [`--input-model`](base-options.md#input-model)
110+
- [`--input-model-ref-strategy`](base-options.md#input-model-ref-strategy)
110111

111112
### K {#k}
112113

docs/cli-reference/quick-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ datamodel-codegen [OPTIONS]
2020
| [`--input`](base-options.md#input) | Specify the input schema file path. |
2121
| [`--input-file-type`](base-options.md#input-file-type) | Specify the input file type for code generation. |
2222
| [`--input-model`](base-options.md#input-model) | Import a Python type or dict schema from a module. |
23+
| [`--input-model-ref-strategy`](base-options.md#input-model-ref-strategy) | Strategy for referenced types when using --input-model. |
2324
| [`--output`](base-options.md#output) | Specify the destination path for generated Python code. |
2425
| [`--url`](base-options.md#url) | Fetch schema from URL with custom HTTP headers. |
2526

@@ -252,6 +253,7 @@ All options sorted alphabetically:
252253
- [`--input`](base-options.md#input) - Specify the input schema file path.
253254
- [`--input-file-type`](base-options.md#input-file-type) - Specify the input file type for code generation.
254255
- [`--input-model`](base-options.md#input-model) - Import a Python type or dict schema from a module.
256+
- [`--input-model-ref-strategy`](base-options.md#input-model-ref-strategy) - Strategy for referenced types when using --input-model.
255257
- [`--keep-model-order`](model-customization.md#keep-model-order) - Keep model definition order as specified in schema.
256258
- [`--keyword-only`](model-customization.md#keyword-only) - Generate dataclasses with keyword-only fields (Python 3.10+)...
257259
- [`--model-extra-keys`](model-customization.md#model-extra-keys) - Add model-level schema extensions to ConfigDict json_schema_...

src/datamodel_code_generator/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
FieldTypeCollisionStrategy,
4040
GraphQLScope,
4141
InputFileType,
42+
InputModelRefStrategy,
4243
ModuleSplitMode,
4344
NamingStrategy,
4445
OpenAPIScope,
@@ -1241,6 +1242,7 @@ def infer_input_type(text: str) -> InputFileType:
12411242
"Error",
12421243
"GeneratedModules",
12431244
"InputFileType",
1245+
"InputModelRefStrategy",
12441246
"InvalidClassNameError",
12451247
"InvalidFileFormatError",
12461248
"LiteralType",

0 commit comments

Comments
 (0)