Skip to content

Commit c771079

Browse files
docs: update CLI reference documentation and prompt data
🤖 Generated by GitHub Actions
1 parent f6d4cbd commit c771079

4 files changed

Lines changed: 94 additions & 1 deletion

File tree

docs/cli-reference/general-options.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
|--------|-------------|
77
| [`--all-exports-collision-strategy`](#all-exports-collision-strategy) | Handle name collisions when exporting recursive module hiera... |
88
| [`--all-exports-scope`](#all-exports-scope) | Generate __all__ exports for child modules in __init__.py fi... |
9+
| [`--allow-remote-refs`](#allow-remote-refs) | Enable fetching of `$ref` targets over HTTP/HTTPS. |
910
| [`--check`](#check) | Verify generated code matches existing output without modify... |
1011
| [`--disable-warnings`](#disable-warnings) | Suppress warning messages during code generation. |
1112
| [`--generate-cli-command`](#generate-cli-command) | Generate CLI command from pyproject.toml configuration. |
@@ -1161,6 +1162,94 @@ Use 'recursive' to include all descendant exports with collision handling.
11611162

11621163
---
11631164

1165+
## `--allow-remote-refs` {#allow-remote-refs}
1166+
1167+
Enable fetching of `$ref` targets over HTTP/HTTPS.
1168+
1169+
When enabled, the generator will resolve `$ref` references that point to remote URLs,
1170+
including relative refs resolved against a schema's `$id` base URL. This is required
1171+
for schemas that reference definitions hosted on external servers.
1172+
1173+
Automatically enabled when using `--url` input.
1174+
1175+
!!! tip "Usage"
1176+
1177+
```bash
1178+
datamodel-codegen --input schema.json --allow-remote-refs # (1)!
1179+
```
1180+
1181+
1. :material-arrow-left: `--allow-remote-refs` - the option documented here
1182+
1183+
??? example "Examples"
1184+
1185+
**Input Schema:**
1186+
1187+
```json
1188+
{
1189+
"$id": "https://example.com/root_id.json",
1190+
"$schema": "http://json-schema.org/draft-07/schema#",
1191+
"definitions": {
1192+
"Person": {
1193+
"$ref": "person.json"
1194+
},
1195+
"OriginalPerson": {
1196+
"$ref": "person.json"
1197+
},
1198+
"Pet": {
1199+
"type": "object",
1200+
"properties": {
1201+
"name": {
1202+
"type": "string",
1203+
"examples": ["dog", "cat"]
1204+
},
1205+
"owner": {
1206+
"$ref": "person.json"
1207+
}
1208+
}
1209+
}
1210+
}
1211+
}
1212+
```
1213+
1214+
**Output:**
1215+
1216+
```python
1217+
# generated by datamodel-codegen:
1218+
# filename: root_id.json
1219+
# timestamp: 2019-07-26T00:00:00+00:00
1220+
1221+
from __future__ import annotations
1222+
1223+
from typing import Any
1224+
1225+
from pydantic import BaseModel, Field, RootModel, conint
1226+
1227+
1228+
class Model(RootModel[Any]):
1229+
root: Any
1230+
1231+
1232+
class Person(BaseModel):
1233+
firstName: str | None = Field(None, description="The person's first name.")
1234+
lastName: str | None = Field(None, description="The person's last name.")
1235+
age: conint(ge=0) | None = Field(
1236+
None, description='Age in years which must be equal to or greater than zero.'
1237+
)
1238+
friends: list[Any] | None = None
1239+
comment: None = None
1240+
1241+
1242+
class OriginalPerson(RootModel[Person]):
1243+
root: Person
1244+
1245+
1246+
class Pet(BaseModel):
1247+
name: str | None = Field(None, examples=['dog', 'cat'])
1248+
owner: Person | None = None
1249+
```
1250+
1251+
---
1252+
11641253
## `--check` {#check}
11651254

11661255
Verify generated code matches existing output without modifying files.

docs/cli-reference/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This documentation is auto-generated from test cases.
1515
| 🎨 [Template Customization](template-customization.md) | 21 | Output formatting and custom rendering |
1616
| 📘 [OpenAPI-only Options](openapi-only-options.md) | 7 | OpenAPI-specific features |
1717
| 📋 [GraphQL-only Options](graphql-only-options.md) | 1 | |
18-
| ⚙️ [General Options](general-options.md) | 15 | Utilities and meta options |
18+
| ⚙️ [General Options](general-options.md) | 16 | Utilities and meta options |
1919
| 📝 [Utility Options](utility-options.md) | 6 | Help, version, debug options |
2020

2121
## All Options
@@ -33,6 +33,7 @@ This documentation is auto-generated from test cases.
3333
- [`--allof-merge-mode`](typing-customization.md#allof-merge-mode)
3434
- [`--allow-extra-fields`](model-customization.md#allow-extra-fields)
3535
- [`--allow-population-by-field-name`](model-customization.md#allow-population-by-field-name)
36+
- [`--allow-remote-refs`](general-options.md#allow-remote-refs)
3637

3738
### B {#b}
3839

docs/cli-reference/quick-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ datamodel-codegen [OPTIONS]
184184
|--------|-------------|
185185
| [`--all-exports-collision-strategy`](general-options.md#all-exports-collision-strategy) | Handle name collisions when exporting recursive module hierarchies. |
186186
| [`--all-exports-scope`](general-options.md#all-exports-scope) | Generate __all__ exports for child modules in __init__.py files. |
187+
| [`--allow-remote-refs`](general-options.md#allow-remote-refs) | Enable fetching of `$ref` targets over HTTP/HTTPS. |
187188
| [`--check`](general-options.md#check) | Verify generated code matches existing output without modifying files. |
188189
| [`--disable-warnings`](general-options.md#disable-warnings) | Suppress warning messages during code generation. |
189190
| [`--generate-cli-command`](general-options.md#generate-cli-command) | Generate CLI command from pyproject.toml configuration. |
@@ -223,6 +224,7 @@ All options sorted alphabetically:
223224
- [`--allof-merge-mode`](typing-customization.md#allof-merge-mode) - Merge constraints from root model references in allOf schema...
224225
- [`--allow-extra-fields`](model-customization.md#allow-extra-fields) - Allow extra fields in generated Pydantic models (extra='allo...
225226
- [`--allow-population-by-field-name`](model-customization.md#allow-population-by-field-name) - Allow Pydantic model population by field name (not just alia...
227+
- [`--allow-remote-refs`](general-options.md#allow-remote-refs) - Enable fetching of `$ref` targets over HTTP/HTTPS.
226228
- [`--base-class`](model-customization.md#base-class) - Specify a custom base class for generated models.
227229
- [`--base-class-map`](model-customization.md#base-class-map) - Specify different base classes for specific models via JSON ...
228230
- [`--capitalize-enum-members`](field-customization.md#capitalize-enum-members) - Capitalize enum member names to UPPER_CASE format.

src/datamodel_code_generator/prompt_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"--allof-merge-mode": "Merge constraints from root model references in allOf schemas.",
1616
"--allow-extra-fields": "Allow extra fields in generated Pydantic models (extra='allow').",
1717
"--allow-population-by-field-name": "Allow Pydantic model population by field name (not just alias).",
18+
"--allow-remote-refs": "Enable fetching of `$ref` targets over HTTP/HTTPS.",
1819
"--base-class": "Specify a custom base class for generated models.",
1920
"--base-class-map": "Specify different base classes for specific models via JSON mapping.",
2021
"--capitalize-enum-members": "Capitalize enum member names to UPPER_CASE format.",

0 commit comments

Comments
 (0)