Skip to content

Commit 0f92860

Browse files
Move --strict-nullable from OpenAPI-only to Field customization (#2727)
* Move --strict-nullable from OpenAPI-only to Field customization * docs: update CLI reference documentation 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8a10962 commit 0f92860

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

docs/cli-reference/model-customization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| [`--reuse-model`](#reuse-model) | Reuse identical model definitions instead of generating dupl... |
2121
| [`--reuse-scope`](#reuse-scope) | Scope for model reuse detection (root or tree). |
2222
| [`--skip-root-model`](#skip-root-model) | Skip generation of root model when schema contains nested de... |
23-
| [`--strict-nullable`](#strict-nullable) | Strictly handle nullable types in OpenAPI schemas. |
23+
| [`--strict-nullable`](#strict-nullable) | Treat default field as a non-nullable field. |
2424
| [`--strip-default-none`](#strip-default-none) | Remove fields with None as default value from generated mode... |
2525
| [`--target-python-version`](#target-python-version) | Target Python version for generated code syntax and imports.... |
2626
| [`--union-mode`](#union-mode) | Union mode for combining anyOf/oneOf schemas (smart or left_... |
@@ -4079,7 +4079,7 @@ object is just a container for $defs and not a meaningful model itself.
40794079

40804080
## `--strict-nullable` {#strict-nullable}
40814081

4082-
Strictly handle nullable types in OpenAPI schemas.
4082+
Treat default field as a non-nullable field.
40834083

40844084
The `--strict-nullable` flag configures the code generation behavior.
40854085

docs/cli-reference/quick-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ datamodel-codegen [OPTIONS]
8989
| [`--reuse-model`](model-customization.md#reuse-model) | Reuse identical model definitions instead of generating duplicates. |
9090
| [`--reuse-scope`](model-customization.md#reuse-scope) | Scope for model reuse detection (root or tree). |
9191
| [`--skip-root-model`](model-customization.md#skip-root-model) | Skip generation of root model when schema contains nested definitions. |
92-
| [`--strict-nullable`](model-customization.md#strict-nullable) | Strictly handle nullable types in OpenAPI schemas. |
92+
| [`--strict-nullable`](model-customization.md#strict-nullable) | Treat default field as a non-nullable field. |
9393
| [`--strip-default-none`](model-customization.md#strip-default-none) | Remove fields with None as default value from generated models. |
9494
| [`--target-python-version`](model-customization.md#target-python-version) | Target Python version for generated code syntax and imports. |
9595
| [`--union-mode`](model-customization.md#union-mode) | Union mode for combining anyOf/oneOf schemas (smart or left_to_right). |
@@ -241,7 +241,7 @@ All options sorted alphabetically:
241241
- [`--skip-root-model`](model-customization.md#skip-root-model) - Skip generation of root model when schema contains nested de...
242242
- [`--snake-case-field`](field-customization.md#snake-case-field) - Convert field names to snake_case format.
243243
- [`--special-field-name-prefix`](field-customization.md#special-field-name-prefix) - Prefix to add to special field names (like reserved keywords...
244-
- [`--strict-nullable`](model-customization.md#strict-nullable) - Strictly handle nullable types in OpenAPI schemas.
244+
- [`--strict-nullable`](model-customization.md#strict-nullable) - Treat default field as a non-nullable field.
245245
- [`--strict-types`](typing-customization.md#strict-types) - Enable strict type validation for specified Python types.
246246
- [`--strip-default-none`](model-customization.md#strip-default-none) - Remove fields with None as default value from generated mode...
247247
- [`--target-python-version`](model-customization.md#target-python-version) - Target Python version for generated code syntax and imports.

src/datamodel_code_generator/arguments.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ def start_section(self, heading: str | None) -> None:
539539
help="Set field name prefix when first character can't be used as Python field name (default: `field`)",
540540
default=None,
541541
)
542+
field_options.add_argument(
543+
"--strict-nullable",
544+
help="Treat default field as a non-nullable field",
545+
action="store_true",
546+
default=None,
547+
)
542548
field_options.add_argument(
543549
"--strip-default-none",
544550
help="Strip default None on fields",
@@ -694,12 +700,6 @@ def start_section(self, heading: str | None) -> None:
694700
nargs="+",
695701
default=None,
696702
)
697-
openapi_options.add_argument(
698-
"--strict-nullable",
699-
help="Treat default field as a non-nullable field (Only OpenAPI)",
700-
action="store_true",
701-
default=None,
702-
)
703703
openapi_options.add_argument(
704704
"--use-operation-id-as-name",
705705
help="use operation id of OpenAPI as class names of models",

tests/main/openapi/test_main_openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ def test_main_openapi_nullable(output_file: Path) -> None:
14801480
golden_output="openapi/nullable_strict_nullable.py",
14811481
)
14821482
def test_main_openapi_nullable_strict_nullable(output_file: Path) -> None:
1483-
"""Strictly handle nullable types in OpenAPI schemas.
1483+
"""Treat default field as a non-nullable field.
14841484
14851485
The `--strict-nullable` flag configures the code generation behavior.
14861486
"""

0 commit comments

Comments
 (0)