@@ -248,7 +248,7 @@ This documentation is auto-generated from test cases.
248248| 🎨 [Template Customization](template-customization.md) | 21 | Output formatting and custom rendering |
249249| 📘 [OpenAPI-only Options](openapi-only-options.md) | 7 | OpenAPI-specific features |
250250| 📋 [GraphQL-only Options](graphql-only-options.md) | 1 | |
251- | ⚙️ [General Options](general-options.md) | 15 | Utilities and meta options |
251+ | ⚙️ [General Options](general-options.md) | 16 | Utilities and meta options |
252252| 📝 [Utility Options](utility-options.md) | 6 | Help, version, debug options |
253253
254254## All Options
@@ -266,6 +266,7 @@ This documentation is auto-generated from test cases.
266266- [`--allof-merge-mode`](typing-customization.md#allof-merge-mode)
267267- [`--allow-extra-fields`](model-customization.md#allow-extra-fields)
268268- [`--allow-population-by-field-name`](model-customization.md#allow-population-by-field-name)
269+ - [`--allow-remote-refs`](general-options.md#allow-remote-refs)
269270
270271### B {#b}
271272
@@ -21564,6 +21565,7 @@ Source: https://datamodel-code-generator.koxudaxi.dev/cli-reference/general-opti
2156421565|--------|-------------|
2156521566| [`--all-exports-collision-strategy`](#all-exports-collision-strategy) | Handle name collisions when exporting recursive module hiera... |
2156621567| [`--all-exports-scope`](#all-exports-scope) | Generate __all__ exports for child modules in __init__.py fi... |
21568+ | [`--allow-remote-refs`](#allow-remote-refs) | Enable fetching of `$ref` targets over HTTP/HTTPS. |
2156721569| [`--check`](#check) | Verify generated code matches existing output without modify... |
2156821570| [`--disable-warnings`](#disable-warnings) | Suppress warning messages during code generation. |
2156921571| [`--generate-cli-command`](#generate-cli-command) | Generate CLI command from pyproject.toml configuration. |
@@ -22719,6 +22721,94 @@ Use 'recursive' to include all descendant exports with collision handling.
2271922721
2272022722---
2272122723
22724+ ## `--allow-remote-refs` {#allow-remote-refs}
22725+
22726+ Enable fetching of `$ref` targets over HTTP/HTTPS.
22727+
22728+ When enabled, the generator will resolve `$ref` references that point to remote URLs,
22729+ including relative refs resolved against a schema's `$id` base URL. This is required
22730+ for schemas that reference definitions hosted on external servers.
22731+
22732+ Automatically enabled when using `--url` input.
22733+
22734+ !!! tip "Usage"
22735+
22736+ ```bash
22737+ datamodel-codegen --input schema.json --allow-remote-refs # (1)!
22738+ ```
22739+
22740+ 1. :material-arrow-left: `--allow-remote-refs` - the option documented here
22741+
22742+ ??? example "Examples"
22743+
22744+ **Input Schema:**
22745+
22746+ ```json
22747+ {
22748+ "$id": "https://example.com/root_id.json",
22749+ "$schema": "http://json-schema.org/draft-07/schema#",
22750+ "definitions": {
22751+ "Person": {
22752+ "$ref": "person.json"
22753+ },
22754+ "OriginalPerson": {
22755+ "$ref": "person.json"
22756+ },
22757+ "Pet": {
22758+ "type": "object",
22759+ "properties": {
22760+ "name": {
22761+ "type": "string",
22762+ "examples": ["dog", "cat"]
22763+ },
22764+ "owner": {
22765+ "$ref": "person.json"
22766+ }
22767+ }
22768+ }
22769+ }
22770+ }
22771+ ```
22772+
22773+ **Output:**
22774+
22775+ ```python
22776+ # generated by datamodel-codegen:
22777+ # filename: root_id.json
22778+ # timestamp: 2019-07-26T00:00:00+00:00
22779+
22780+ from __future__ import annotations
22781+
22782+ from typing import Any
22783+
22784+ from pydantic import BaseModel, Field, RootModel, conint
22785+
22786+
22787+ class Model(RootModel[Any]):
22788+ root: Any
22789+
22790+
22791+ class Person(BaseModel):
22792+ firstName: str | None = Field(None, description="The person's first name.")
22793+ lastName: str | None = Field(None, description="The person's last name.")
22794+ age: conint(ge=0) | None = Field(
22795+ None, description='Age in years which must be equal to or greater than zero.'
22796+ )
22797+ friends: list[Any] | None = None
22798+ comment: None = None
22799+
22800+
22801+ class OriginalPerson(RootModel[Person]):
22802+ root: Person
22803+
22804+
22805+ class Pet(BaseModel):
22806+ name: str | None = Field(None, examples=['dog', 'cat'])
22807+ owner: Person | None = None
22808+ ```
22809+
22810+ ---
22811+
2272222812## `--check` {#check}
2272322813
2272422814Verify generated code matches existing output without modifying files.
@@ -23993,6 +24083,7 @@ datamodel-codegen [OPTIONS]
2399324083|--------|-------------|
2399424084| [`--all-exports-collision-strategy`](general-options.md#all-exports-collision-strategy) | Handle name collisions when exporting recursive module hierarchies. |
2399524085| [`--all-exports-scope`](general-options.md#all-exports-scope) | Generate __all__ exports for child modules in __init__.py files. |
24086+ | [`--allow-remote-refs`](general-options.md#allow-remote-refs) | Enable fetching of `$ref` targets over HTTP/HTTPS. |
2399624087| [`--check`](general-options.md#check) | Verify generated code matches existing output without modifying files. |
2399724088| [`--disable-warnings`](general-options.md#disable-warnings) | Suppress warning messages during code generation. |
2399824089| [`--generate-cli-command`](general-options.md#generate-cli-command) | Generate CLI command from pyproject.toml configuration. |
@@ -24032,6 +24123,7 @@ All options sorted alphabetically:
2403224123- [`--allof-merge-mode`](typing-customization.md#allof-merge-mode) - Merge constraints from root model references in allOf schema...
2403324124- [`--allow-extra-fields`](model-customization.md#allow-extra-fields) - Allow extra fields in generated Pydantic models (extra='allo...
2403424125- [`--allow-population-by-field-name`](model-customization.md#allow-population-by-field-name) - Allow Pydantic model population by field name (not just alia...
24126+ - [`--allow-remote-refs`](general-options.md#allow-remote-refs) - Enable fetching of `$ref` targets over HTTP/HTTPS.
2403524127- [`--base-class`](model-customization.md#base-class) - Specify a custom base class for generated models.
2403624128- [`--base-class-map`](model-customization.md#base-class-map) - Specify different base classes for specific models via JSON ...
2403724129- [`--capitalize-enum-members`](field-customization.md#capitalize-enum-members) - Capitalize enum member names to UPPER_CASE format.
0 commit comments