You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Parser subclass signature change - The `Parser` base class now requires two generic type parameters: `Parser[ParserConfigT, SchemaFeaturesT]` instead of just `Parser[ParserConfigT]`. Custom parser subclasses must be updated to include the second type parameter. (#2929)
* New abstract `schema_features` property required - Custom parser subclasses must now implement the `schema_features` abstract property that returns a `JsonSchemaFeatures` (or subclass) instance. (#2929)
26
+
```python
27
+
from functools import cached_property
28
+
from datamodel_code_generator.parser.schema_version import JsonSchemaFeatures
29
+
from datamodel_code_generator.enums import JsonSchemaVersion
* Parser `_create_default_config` refactored to use class variable - Subclasses that override `_create_default_config` should now set the `_config_class_name` class variable instead. The base implementation uses this variable to dynamically instantiate the correct config class. (#2929)
# No need to override _create_default_config if using standard config creation
44
+
```
45
+
* Template condition for default values changed - If you use custom Jinja2 templates based on `BaseModel_root.jinja2` or `RootModel.jinja2`, the condition for including default values has changed from `field.required` to `(field.required and not field.has_default)`. Update your custom templates if you override these files. (#2960)
46
+
47
+
### Code Generation Changes
48
+
* RootModel default values now included in generated code - Previously, default values defined in JSON Schema or OpenAPI specifications for root models were not being applied to the generated Pydantic code. Now these defaults are correctly included. For example, a schema defining a root model with `default: 1` will generate `__root__: int = 1` (Pydantic v1) or `root: int = 1` (Pydantic v2) instead of just `__root__: int` or `root: int`. This may affect code that relied on the previous behavior where RootModel fields had no default values. (#2960)
49
+
* Required fields with list defaults now use `default_factory` - Previously, required fields with list-type defaults (like `__root__: list[ID] = ['abc', 'efg']`) were generated with direct list assignments. Now they correctly use `Field(default_factory=lambda: ...)` which follows Python best practices for mutable defaults. This changes the structure of generated code for root models and similar patterns with list defaults. (#2958)
50
+
Before:
51
+
```python
52
+
classFamily(BaseModel):
53
+
__root__: list[ID] = ['abc', 'efg']
54
+
```
55
+
After:
56
+
```python
57
+
classFamily(BaseModel):
58
+
__root__: list[ID] = Field(
59
+
default_factory=lambda: [ID.parse_obj(v) for v in ['abc', 'efg']]
60
+
)
61
+
```
62
+
63
+
## What's Changed
64
+
* Separate pytest-benchmark into dedicated benchmark dependency group by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2937
65
+
* Support ClassVar for Pydantic v2 by @ubaumann in https://github.com/koxudaxi/datamodel-code-generator/pull/2920
66
+
* Add schema version detection and feature flags by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2924
67
+
* Fix MRO ordering for multiple inheritance in GraphQL and JSON Schema/OpenAPI by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2941
68
+
* Add schema_features property to parsers for version detection by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2929
69
+
* Fix $ref handling in request-response mode for readOnly/writeOnly schemas by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2942
70
+
* Ensure codecov upload runs even when coverage check fails by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2944
71
+
* Add FeatureMetadata to schema feature classes for doc generation by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2945
72
+
* Add schema-docs auto-generation with pre-commit and CI by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2949
73
+
* Add comprehensive feature metadata to schema version dataclasses by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2946
74
+
* fix: move UnionMode import outside TYPE_CHECKING for Pydantic runtime… by @phil65 in https://github.com/koxudaxi/datamodel-code-generator/pull/2950
75
+
* Fix IndexError when using --reuse-scope=tree with single file output by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2954
76
+
* Add --use-closed-typed-dict option to control PEP 728 TypedDict generation by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2956
77
+
* Fix RootModel default value not being applied by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2960
78
+
* Fix required list fields ignoring empty default values by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2958
79
+
* Add GenerateConfig lazy import from top-level module by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2961
80
+
* Fix allOf array property merging to preserve child $ref by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2962
81
+
* Fix array RootModel default value handling in parser by @koxudaxi in https://github.com/koxudaxi/datamodel-code-generator/pull/2963
82
+
* Fix bug in handling of graphql empty list defaults by @rpmcginty in https://github.com/koxudaxi/datamodel-code-generator/pull/2948
83
+
84
+
## New Contributors
85
+
*@ubaumann made their first contribution in https://github.com/koxudaxi/datamodel-code-generator/pull/2920
86
+
*@phil65 made their first contribution in https://github.com/koxudaxi/datamodel-code-generator/pull/2950
0 commit comments