Skip to content

Commit ec5c87a

Browse files
author
Adam Gray
committed
One more missed case
1 parent b2c73fd commit ec5c87a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

openapi_python_client/openapi_parser/properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def get_type_string(self) -> str:
168168

169169
def transform(self) -> str:
170170
""" Output to the template, convert this Enum into a JSONable value """
171-
return f"{self.name}.value"
171+
return f"{self.python_name}.value"
172172

173173
def constructor_from_dict(self, dict_name: str) -> str:
174174
""" How to load this property from a dict (used in generated model from_dict function """

tests/test_openapi_parser/test_properties.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ def test_to_string(self, mocker):
2020
name = mocker.MagicMock()
2121
p = Property(name=name, required=True, default=None)
2222
get_type_string = mocker.patch.object(p, "get_type_string")
23+
snake_case = mocker.patch(f"openapi_python_client.utils.snake_case")
2324

24-
assert p.to_string() == f"{name}: {get_type_string()}"
25+
assert p.to_string() == f"{snake_case(name)}: {get_type_string()}"
2526
p.required = False
26-
assert p.to_string() == f"{name}: {get_type_string()} = None"
27+
assert p.to_string() == f"{snake_case(name)}: {get_type_string()} = None"
2728

2829
p.default = "TEST"
29-
assert p.to_string() == f"{name}: {get_type_string()} = TEST"
30+
assert p.to_string() == f"{snake_case(name)}: {get_type_string()} = TEST"
3031

3132
def test_transform(self, mocker):
3233
from openapi_python_client.openapi_parser.properties import Property
3334

3435
name = mocker.MagicMock()
3536
p = Property(name=name, required=True, default=None)
36-
assert p.transform() == name
37+
snake_case = mocker.patch(f"openapi_python_client.utils.snake_case")
38+
assert p.transform() == snake_case(name)
3739

3840
def test_constructor_from_dict(self, mocker):
3941
from openapi_python_client.openapi_parser.properties import Property
@@ -150,14 +152,14 @@ def test_get_type_string(self, mocker):
150152
assert enum_property.get_type_string() == "Optional[MyTestEnum]"
151153

152154
def test_transform(self, mocker):
153-
name = mocker.MagicMock()
155+
name = "thePropertyName"
154156
mocker.patch(f"{MODULE_NAME}.Reference.from_ref")
155157

156158
from openapi_python_client.openapi_parser.properties import EnumProperty
157159

158160
enum_property = EnumProperty(name=name, required=True, default=None, values={})
159161

160-
assert enum_property.transform() == f"{name}.value"
162+
assert enum_property.transform() == f"the_property_name.value"
161163

162164
def test_constructor_from_dict(self, mocker):
163165
fake_reference = mocker.MagicMock(class_name="MyTestEnum")

0 commit comments

Comments
 (0)