|
10 | 10 | | [`--input-model`](#input-model) | Import a Python type or dict schema from a module. | |
11 | 11 | | [`--input-model-ref-strategy`](#input-model-ref-strategy) | Strategy for referenced types when using --input-model. | |
12 | 12 | | [`--output`](#output) | Specify the destination path for generated Python code. | |
| 13 | +| [`--schema-version`](#schema-version) | Schema version to use for parsing. | |
| 14 | +| [`--schema-version-mode`](#schema-version-mode) | Schema version validation mode. | |
13 | 15 | | [`--url`](#url) | Fetch schema from URL with custom HTTP headers. | |
14 | 16 |
|
15 | 17 | --- |
@@ -326,6 +328,76 @@ is written to stdout. |
326 | 328 |
|
327 | 329 | --- |
328 | 330 |
|
| 331 | +## `--schema-version` {#schema-version} |
| 332 | + |
| 333 | +Schema version to use for parsing. |
| 334 | + |
| 335 | +The `--schema-version` option specifies the schema version to use instead of auto-detection. |
| 336 | +Valid values depend on input type: JsonSchema (draft-04, draft-06, draft-07, 2019-09, 2020-12) |
| 337 | +or OpenAPI (3.0, 3.1). Default is 'auto' (detected from $schema or openapi field). |
| 338 | + |
| 339 | +!!! tip "Usage" |
| 340 | + |
| 341 | + ```bash |
| 342 | + datamodel-codegen --input schema.json --schema-version draft-07 # (1)! |
| 343 | + ``` |
| 344 | + |
| 345 | + 1. :material-arrow-left: `--schema-version` - the option documented here |
| 346 | + |
| 347 | +??? example "Examples" |
| 348 | + |
| 349 | + **Input Schema:** |
| 350 | + |
| 351 | + ```json |
| 352 | + { |
| 353 | + "$schema": "http://json-schema.org/draft-07/schema", |
| 354 | + "type": "object", |
| 355 | + "properties": {"s": {"type": ["string"]}}, |
| 356 | + "required": ["s"] |
| 357 | + } |
| 358 | + ``` |
| 359 | + |
| 360 | + **Output:** |
| 361 | + |
| 362 | + > **Error:** File not found: jsonschema/simple_string.py |
| 363 | + |
| 364 | +--- |
| 365 | + |
| 366 | +## `--schema-version-mode` {#schema-version-mode} |
| 367 | + |
| 368 | +Schema version validation mode. |
| 369 | + |
| 370 | +The `--schema-version-mode` option controls how schema version validation is performed. |
| 371 | +'lenient' (default): accept all features regardless of version. |
| 372 | +'strict': warn on features outside the declared/detected version. |
| 373 | + |
| 374 | +!!! tip "Usage" |
| 375 | + |
| 376 | + ```bash |
| 377 | + datamodel-codegen --input schema.json --schema-version-mode lenient # (1)! |
| 378 | + ``` |
| 379 | + |
| 380 | + 1. :material-arrow-left: `--schema-version-mode` - the option documented here |
| 381 | + |
| 382 | +??? example "Examples" |
| 383 | + |
| 384 | + **Input Schema:** |
| 385 | + |
| 386 | + ```json |
| 387 | + { |
| 388 | + "$schema": "http://json-schema.org/draft-07/schema", |
| 389 | + "type": "object", |
| 390 | + "properties": {"s": {"type": ["string"]}}, |
| 391 | + "required": ["s"] |
| 392 | + } |
| 393 | + ``` |
| 394 | + |
| 395 | + **Output:** |
| 396 | + |
| 397 | + > **Error:** File not found: jsonschema/simple_string.py |
| 398 | + |
| 399 | +--- |
| 400 | + |
329 | 401 | ## `--url` {#url} |
330 | 402 |
|
331 | 403 | Fetch schema from URL with custom HTTP headers. |
|
0 commit comments