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
{{ message }}
Repository navigation
Commit fb00a27
Browse filesBrowse the repository at this point in the historyBrowse files
fix: support default {} on freeform object schemas
A schema declared as `type: object` with `additionalProperties: true` and no
declared properties (often appearing inside an `anyOf` with `null`) could not
carry a `default: {}`. `ModelProperty.convert_value` rejected the default with
`ModelProperty cannot have a default value`, which propagated up as a warning
and silently dropped the enclosing schema and every endpoint referencing it.
`ModelProperty.convert_value` now accepts the empty dict on a freeform model
and emits a `ClassName()` constructor call. When `required_properties` has not
yet been populated, the check falls back to the raw schema (`data.properties`,
`data.allOf`, `data.anyOf`, `data.oneOf`) so referenced schemas not yet
processed still get the correct decision.
A default value also forces the generated client to import the inner model at
runtime rather than only under `TYPE_CHECKING`, otherwise the default
initializer would `NameError` at class-definition time. `get_imports` and
`get_lazy_imports` are updated accordingly on both `ModelProperty` and
`UnionProperty` so inner-property imports are promoted when the property has a
non-`None` default.
Tests: a functional test in `end_to_end_tests/functional_tests` covers the
inline spec, and unit tests in
`tests/test_parser/test_properties/test_model_property.py` cover the new
branches in `convert_value`, `get_imports`, and `get_lazy_imports`.
# Support `default: {}` on freeform object schemas
6
+
7
+
A schema declared as `type: object` with `additionalProperties: true` and no declared properties (often appearing inside an `anyOf` with `null`) could not carry a `default: {}`. The parser rejected the default with `ModelProperty cannot have a default value`, which silently dropped the enclosing schema and every endpoint that referenced it.
8
+
9
+
The default `{}` is now accepted on such freeform models and generates an empty-container initializer. The imports of inner models with a non-`None` default are also promoted from lazy `TYPE_CHECKING` imports to runtime imports, so the generated default expression resolves correctly at class-definition time.
0 commit comments