From cf35779aa4eb7e079ab677b2f8d947808a418f27 Mon Sep 17 00:00:00 2001 From: George Murray Date: Wed, 13 Oct 2021 16:50:47 -0700 Subject: [PATCH] fix: in openapi enums breaks client generation BNCH-32257 --- openapi_python_client/parser/properties/enum_property.py | 4 +++- tests/test_parser/test_properties/test_init.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openapi_python_client/parser/properties/enum_property.py b/openapi_python_client/parser/properties/enum_property.py index 6938dd716..f28a4baf1 100644 --- a/openapi_python_client/parser/properties/enum_property.py +++ b/openapi_python_client/parser/properties/enum_property.py @@ -50,7 +50,9 @@ def values_from_list(values: List[ValueType]) -> Dict[str, ValueType]: else: output[f"VALUE_{value}"] = value continue - if value[0].isalpha(): + if value is None: + continue + if value and value[0].isalpha(): key = value.upper() else: key = f"VALUE_{i}" diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index 604b1bd1d..9e856e26f 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -456,7 +456,7 @@ def test_get_imports(self, mocker): def test_values_from_list(self): from openapi_python_client.parser.properties import EnumProperty - data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces"] + data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces", "", None] result = EnumProperty.values_from_list(data) @@ -468,6 +468,7 @@ def test_values_from_list(self): "VALUE_4": 4, "VALUE_NEGATIVE_3": -3, "A_THING_WITH_SPACES": "a Thing WIth spaces", + "VALUE_7": "", } def test_values_from_list_duplicate(self):