File tree Expand file tree Collapse file tree
src/datamodel_code_generator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
40844084The ` --strict-nullable ` flag configures the code generation behavior.
40854085
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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+ )
542548field_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- )
703703openapi_options .add_argument (
704704 "--use-operation-id-as-name" ,
705705 help = "use operation id of OpenAPI as class names of models" ,
Original file line number Diff line number Diff line change @@ -1480,7 +1480,7 @@ def test_main_openapi_nullable(output_file: Path) -> None:
14801480 golden_output = "openapi/nullable_strict_nullable.py" ,
14811481)
14821482def 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 """
You can’t perform that action at this time.
0 commit comments