When a property is a union of schemas that are all object/model types
(e.g. `oneOf: [ModelA, ModelB]`), `union_property.py.jinja`'s `transform`
macro generated a per-member `isinstance` dispatch in `to_dict()`, even
though every branch does the exact same thing (`.to_dict()`). The check
never affects the outcome, since every generated model class converts
identically.
Detect when every union member is model-shaped and skip the per-member
dispatch:
- required: unconditional `dest = source.to_dict()`, no isinstance at all
- optional: `else: dest = source.to_dict()` after the existing Unset guard
- optional request bodies (`skip_unset=True`, no Unset guard emitted
yet): guard with `if not isinstance(source, Unset)` instead of the
previous single-member `isinstance(source, ModelX)` check
Mixed unions (model + primitive/enum/None/Any members) are unaffected
and keep their existing per-member dispatch, since those branches
genuinely differ in behavior.
Discussion: openapi-generators#1486
When a property is a union of schemas that are all object/model types (e.g. oneOf: [ModelA, ModelB]), union_property.py.jinja's transform macro generated a per-member isinstance dispatch in to_dict(), even though every branch does the exact same thing (.to_dict()). The check never affects the outcome, since every generated model class converts identically.
Detect when every union member is model-shaped and skip the per-member dispatch:
Mixed unions (model + primitive/enum/None/Any members) are unaffected and keep their existing per-member dispatch, since those branches genuinely differ in behavior.
pdm run check run succesfully.
Discussion: #1486
Full disclosure: I used Claude Sonnet to help with the development. Feel free to point our any AI slop, happy to fix it