Skip to content

Commit 2f0b272

Browse files
committed
Tuples and unions are only used if there are truly more then one item there - Part 2
1 parent aee89fc commit 2f0b272

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/openapi_python_generator/language_converters/python/model_generator.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ def type_converter(schema: Schema, required: bool = False) -> TypeConversion:
5959
if len(conversions) == 1:
6060
converted_type = conversions[0].converted_type
6161
else:
62-
converted_type = ",".join([i.converted_type for i in conversions])
62+
converted_type = (
63+
"Tuple[" + ",".join([i.converted_type for i in conversions]) + "]"
64+
)
6365

64-
converted_type = pre_type + "Tuple[" + converted_type + "]" + post_type
66+
converted_type = pre_type + converted_type + post_type
6567
import_types = [
6668
i.import_types[0] for i in conversions if i.import_types is not None
6769
]
@@ -90,9 +92,11 @@ def type_converter(schema: Schema, required: bool = False) -> TypeConversion:
9092
if len(conversions) == 1:
9193
converted_type = conversions[0].converted_type
9294
else:
93-
converted_type = ",".join([i.converted_type for i in conversions])
95+
converted_type = (
96+
"Union[" + ",".join([i.converted_type for i in conversions]) + "]"
97+
)
9498

95-
converted_type = pre_type + "Union[" + converted_type + "]" + post_type
99+
converted_type = pre_type + converted_type + post_type
96100
import_types = list(
97101
itertools.chain(
98102
*[i.import_types for i in conversions if i.import_types is not None]

0 commit comments

Comments
 (0)