Skip to content

Commit 4209fb6

Browse files
committed
Fix merging inline objects
1 parent 3bfaef9 commit 4209fb6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

end_to_end_tests/golden-record/my_test_api_client/models/model_with_merged_properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ class ModelWithMergedProperties:
1616
"""
1717
Attributes:
1818
simple_string (Union[Unset, str]): extended simpleString description Default: 'new default'.
19-
string_to_enum (Union[Unset, ModelWithMergedPropertiesStringToEnum]):
19+
string_to_enum (Union[Unset, ModelWithMergedPropertiesStringToEnum]): Default: 'a'.
2020
string_to_date (Union[Unset, datetime.date]):
2121
number_to_int (Union[Unset, int]):
2222
any_to_string (Union[Unset, str]): Default: 'x'.
2323
"""
2424

2525
simple_string: Union[Unset, str] = "new default"
26-
string_to_enum: Union[Unset, ModelWithMergedPropertiesStringToEnum] = UNSET
26+
string_to_enum: Union[Unset, ModelWithMergedPropertiesStringToEnum] = "a"
2727
string_to_date: Union[Unset, datetime.date] = UNSET
2828
number_to_int: Union[Unset, int] = UNSET
2929
any_to_string: Union[Unset, str] = "x"

openapi_python_client/parser/properties/model_property.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None:
275275
properties[merged_prop.name] = merged_prop
276276
return None
277277

278-
unprocessed_props = data.properties or {}
278+
unprocessed_props: list[tuple[str, oai.Reference | oai.Schema]] = (
279+
list(data.properties.items()) if data.properties else []
280+
)
279281
for sub_prop in data.allOf:
280282
if isinstance(sub_prop, oai.Reference):
281283
ref_path = parse_reference_path(sub_prop.ref)
@@ -297,10 +299,10 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None:
297299
return err
298300
schemas.add_dependencies(ref_path=ref_path, roots=roots)
299301
else:
300-
unprocessed_props.update(sub_prop.properties or {})
302+
unprocessed_props.extend(sub_prop.properties.items() if sub_prop.properties else [])
301303
required_set.update(sub_prop.required or [])
302304

303-
for key, value in unprocessed_props.items():
305+
for key, value in unprocessed_props:
304306
prop_required = key in required_set
305307
prop_or_error: Property | (PropertyError | None)
306308
prop_or_error, schemas = property_from_data(

0 commit comments

Comments
 (0)