Skip to content

Commit 22361fe

Browse files
committed
add test for merging lists
1 parent db90641 commit 22361fe

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

openapi_python_client/parser/properties/merge_properties.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def _merge_same_type(prop1: Property, prop2: Property) -> Property | None | Prop
7676
return prop1
7777

7878
if isinstance(prop1, ListProperty) and isinstance(prop2, ListProperty):
79-
# There's no clear way to represent the intersection of two different list types. Fail in this case.
8079
inner_property = merge_properties(prop1.inner_property, prop2.inner_property) # type: ignore
8180
if isinstance(inner_property, PropertyError):
8281
return PropertyError(detail=f"can't merge list properties: {inner_property.detail}")

tests/test_parser/test_properties/test_merge_properties.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,18 @@ def test_merge_string_with_formatted_string(
219219

220220
assert isinstance(merge_properties(string_prop_with_invalid_default, formatted_prop), PropertyError)
221221
assert isinstance(merge_properties(formatted_prop, string_prop_with_invalid_default), PropertyError)
222+
223+
224+
def test_merge_lists(int_property_factory, list_property_factory, string_property_factory):
225+
string_prop_1 = string_property_factory(description="desc1")
226+
string_prop_2 = string_property_factory(example="desc2")
227+
int_prop = int_property_factory()
228+
list_prop_1 = list_property_factory(inner_property=string_prop_1)
229+
list_prop_2 = list_property_factory(inner_property=string_prop_2)
230+
list_prop_3 = list_property_factory(inner_property=int_prop)
231+
232+
assert merge_properties(list_prop_1, list_prop_2) == evolve(
233+
list_prop_1, inner_property=merge_properties(string_prop_1, string_prop_2)
234+
)
235+
236+
assert isinstance(merge_properties(list_prop_1, list_prop_3), PropertyError)

0 commit comments

Comments
 (0)