Skip to content

Commit 4990254

Browse files
committed
fix(cases): treat numbers as words when processing cases
1 parent 3aacf5e commit 4990254

12 files changed

+99
-94
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ...client import Client
66
from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody
7-
from ...models.test_inline_objects_response200 import TestInlineObjectsResponse200
7+
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200
88
from ...types import Response
99

1010

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
)
1919
from .model_with_additional_properties_refed import ModelWithAdditionalPropertiesRefed
2020
from .model_with_any_json_properties import ModelWithAnyJsonProperties
21-
from .model_with_any_json_properties_additional_property_type0 import ModelWithAnyJsonPropertiesAdditionalPropertyType0
21+
from .model_with_any_json_properties_additional_property_type_0 import ModelWithAnyJsonPropertiesAdditionalPropertyType0
2222
from .model_with_primitive_additional_properties import ModelWithPrimitiveAdditionalProperties
2323
from .model_with_primitive_additional_properties_a_date_holder import ModelWithPrimitiveAdditionalPropertiesADateHolder
2424
from .model_with_property_ref import ModelWithPropertyRef
2525
from .model_with_union_property import ModelWithUnionProperty
2626
from .model_with_union_property_inlined import ModelWithUnionPropertyInlined
27-
from .model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0
28-
from .model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1
27+
from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
28+
from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1
2929
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
30-
from .test_inline_objects_response200 import TestInlineObjectsResponse200
30+
from .test_inline_objects_response_200 import TestInlineObjectsResponse200
3131
from .validation_error import ValidationError

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

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,20 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
186186

187187
def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.datetime]:
188188
try:
189-
a_camel_date_time_type0: datetime.datetime
189+
a_camel_date_time_type_0: datetime.datetime
190190
if not isinstance(data, str):
191191
raise TypeError()
192-
a_camel_date_time_type0 = isoparse(data)
192+
a_camel_date_time_type_0 = isoparse(data)
193193

194-
return a_camel_date_time_type0
194+
return a_camel_date_time_type_0
195195
except: # noqa: E722
196196
pass
197197
if not isinstance(data, str):
198198
raise TypeError()
199-
a_camel_date_time_type1: datetime.date
200-
a_camel_date_time_type1 = isoparse(data).date()
199+
a_camel_date_time_type_1: datetime.date
200+
a_camel_date_time_type_1 = isoparse(data).date()
201201

202-
return a_camel_date_time_type1
202+
return a_camel_date_time_type_1
203203

204204
a_camel_date_time = _parse_a_camel_date_time(d.pop("aCamelDateTime"))
205205

@@ -209,20 +209,20 @@ def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.date
209209

210210
def _parse_one_of_models(data: object) -> Union[FreeFormModel, ModelWithUnionProperty]:
211211
try:
212-
one_of_models_type0: FreeFormModel
212+
one_of_models_type_0: FreeFormModel
213213
if not isinstance(data, dict):
214214
raise TypeError()
215-
one_of_models_type0 = FreeFormModel.from_dict(data)
215+
one_of_models_type_0 = FreeFormModel.from_dict(data)
216216

217-
return one_of_models_type0
217+
return one_of_models_type_0
218218
except: # noqa: E722
219219
pass
220220
if not isinstance(data, dict):
221221
raise TypeError()
222-
one_of_models_type1: ModelWithUnionProperty
223-
one_of_models_type1 = ModelWithUnionProperty.from_dict(data)
222+
one_of_models_type_1: ModelWithUnionProperty
223+
one_of_models_type_1 = ModelWithUnionProperty.from_dict(data)
224224

225-
return one_of_models_type1
225+
return one_of_models_type_1
226226

227227
one_of_models = _parse_one_of_models(d.pop("one_of_models"))
228228

@@ -267,47 +267,47 @@ def _parse_nullable_one_of_models(data: object) -> Union[FreeFormModel, ModelWit
267267
if data is None:
268268
return data
269269
try:
270-
nullable_one_of_models_type0: FreeFormModel
270+
nullable_one_of_models_type_0: FreeFormModel
271271
if not isinstance(data, dict):
272272
raise TypeError()
273-
nullable_one_of_models_type0 = FreeFormModel.from_dict(data)
273+
nullable_one_of_models_type_0 = FreeFormModel.from_dict(data)
274274

275-
return nullable_one_of_models_type0
275+
return nullable_one_of_models_type_0
276276
except: # noqa: E722
277277
pass
278278
if not isinstance(data, dict):
279279
raise TypeError()
280-
nullable_one_of_models_type1: ModelWithUnionProperty
281-
nullable_one_of_models_type1 = ModelWithUnionProperty.from_dict(data)
280+
nullable_one_of_models_type_1: ModelWithUnionProperty
281+
nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data)
282282

283-
return nullable_one_of_models_type1
283+
return nullable_one_of_models_type_1
284284

285285
nullable_one_of_models = _parse_nullable_one_of_models(d.pop("nullable_one_of_models"))
286286

287287
def _parse_not_required_one_of_models(data: object) -> Union[FreeFormModel, ModelWithUnionProperty, Unset]:
288288
if isinstance(data, Unset):
289289
return data
290290
try:
291-
not_required_one_of_models_type0: Union[Unset, FreeFormModel]
291+
not_required_one_of_models_type_0: Union[Unset, FreeFormModel]
292292
if not isinstance(data, dict):
293293
raise TypeError()
294-
not_required_one_of_models_type0 = UNSET
295-
_not_required_one_of_models_type0 = data
296-
if not isinstance(_not_required_one_of_models_type0, Unset):
297-
not_required_one_of_models_type0 = FreeFormModel.from_dict(_not_required_one_of_models_type0)
294+
not_required_one_of_models_type_0 = UNSET
295+
_not_required_one_of_models_type_0 = data
296+
if not isinstance(_not_required_one_of_models_type_0, Unset):
297+
not_required_one_of_models_type_0 = FreeFormModel.from_dict(_not_required_one_of_models_type_0)
298298

299-
return not_required_one_of_models_type0
299+
return not_required_one_of_models_type_0
300300
except: # noqa: E722
301301
pass
302302
if not isinstance(data, dict):
303303
raise TypeError()
304-
not_required_one_of_models_type1: Union[Unset, ModelWithUnionProperty]
305-
not_required_one_of_models_type1 = UNSET
306-
_not_required_one_of_models_type1 = data
307-
if not isinstance(_not_required_one_of_models_type1, Unset):
308-
not_required_one_of_models_type1 = ModelWithUnionProperty.from_dict(_not_required_one_of_models_type1)
304+
not_required_one_of_models_type_1: Union[Unset, ModelWithUnionProperty]
305+
not_required_one_of_models_type_1 = UNSET
306+
_not_required_one_of_models_type_1 = data
307+
if not isinstance(_not_required_one_of_models_type_1, Unset):
308+
not_required_one_of_models_type_1 = ModelWithUnionProperty.from_dict(_not_required_one_of_models_type_1)
309309

310-
return not_required_one_of_models_type1
310+
return not_required_one_of_models_type_1
311311

312312
not_required_one_of_models = _parse_not_required_one_of_models(d.pop("not_required_one_of_models", UNSET))
313313

@@ -319,31 +319,31 @@ def _parse_not_required_nullable_one_of_models(
319319
if isinstance(data, Unset):
320320
return data
321321
try:
322-
not_required_nullable_one_of_models_type0: Union[Unset, FreeFormModel]
322+
not_required_nullable_one_of_models_type_0: Union[Unset, FreeFormModel]
323323
if not isinstance(data, dict):
324324
raise TypeError()
325-
not_required_nullable_one_of_models_type0 = UNSET
326-
_not_required_nullable_one_of_models_type0 = data
327-
if not isinstance(_not_required_nullable_one_of_models_type0, Unset):
328-
not_required_nullable_one_of_models_type0 = FreeFormModel.from_dict(
329-
_not_required_nullable_one_of_models_type0
325+
not_required_nullable_one_of_models_type_0 = UNSET
326+
_not_required_nullable_one_of_models_type_0 = data
327+
if not isinstance(_not_required_nullable_one_of_models_type_0, Unset):
328+
not_required_nullable_one_of_models_type_0 = FreeFormModel.from_dict(
329+
_not_required_nullable_one_of_models_type_0
330330
)
331331

332-
return not_required_nullable_one_of_models_type0
332+
return not_required_nullable_one_of_models_type_0
333333
except: # noqa: E722
334334
pass
335335
try:
336-
not_required_nullable_one_of_models_type1: Union[Unset, ModelWithUnionProperty]
336+
not_required_nullable_one_of_models_type_1: Union[Unset, ModelWithUnionProperty]
337337
if not isinstance(data, dict):
338338
raise TypeError()
339-
not_required_nullable_one_of_models_type1 = UNSET
340-
_not_required_nullable_one_of_models_type1 = data
341-
if not isinstance(_not_required_nullable_one_of_models_type1, Unset):
342-
not_required_nullable_one_of_models_type1 = ModelWithUnionProperty.from_dict(
343-
_not_required_nullable_one_of_models_type1
339+
not_required_nullable_one_of_models_type_1 = UNSET
340+
_not_required_nullable_one_of_models_type_1 = data
341+
if not isinstance(_not_required_nullable_one_of_models_type_1, Unset):
342+
not_required_nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(
343+
_not_required_nullable_one_of_models_type_1
344344
)
345345

346-
return not_required_nullable_one_of_models_type1
346+
return not_required_nullable_one_of_models_type_1
347347
except: # noqa: E722
348348
pass
349349
return cast(Union[FreeFormModel, ModelWithUnionProperty, None, Unset, str], data)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import attr
44

5-
from ..models.model_with_any_json_properties_additional_property_type0 import (
5+
from ..models.model_with_any_json_properties_additional_property_type_0 import (
66
ModelWithAnyJsonPropertiesAdditionalPropertyType0,
77
)
88

@@ -46,21 +46,21 @@ def _parse_additional_property(
4646
data: object,
4747
) -> Union[List[str], ModelWithAnyJsonPropertiesAdditionalPropertyType0, bool, float, int, str]:
4848
try:
49-
additional_property_type0: ModelWithAnyJsonPropertiesAdditionalPropertyType0
49+
additional_property_type_0: ModelWithAnyJsonPropertiesAdditionalPropertyType0
5050
if not isinstance(data, dict):
5151
raise TypeError()
52-
additional_property_type0 = ModelWithAnyJsonPropertiesAdditionalPropertyType0.from_dict(data)
52+
additional_property_type_0 = ModelWithAnyJsonPropertiesAdditionalPropertyType0.from_dict(data)
5353

54-
return additional_property_type0
54+
return additional_property_type_0
5555
except: # noqa: E722
5656
pass
5757
try:
58-
additional_property_type1: List[str]
58+
additional_property_type_1: List[str]
5959
if not isinstance(data, list):
6060
raise TypeError()
61-
additional_property_type1 = cast(List[str], data)
61+
additional_property_type_1 = cast(List[str], data)
6262

63-
return additional_property_type1
63+
return additional_property_type_1
6464
except: # noqa: E722
6565
pass
6666
return cast(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def to_dict(self) -> Dict[str, Any]:
2222
@classmethod
2323
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
2424
d = src_dict.copy()
25-
model_with_any_json_properties_additional_property_type0 = cls()
25+
model_with_any_json_properties_additional_property_type_0 = cls()
2626

27-
model_with_any_json_properties_additional_property_type0.additional_properties = d
28-
return model_with_any_json_properties_additional_property_type0
27+
model_with_any_json_properties_additional_property_type_0.additional_properties = d
28+
return model_with_any_json_properties_additional_property_type_0
2929

3030
@property
3131
def additional_keys(self) -> List[str]:

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ def _parse_a_property(data: object) -> Union[AnEnum, AnIntEnum, Unset]:
4444
if isinstance(data, Unset):
4545
return data
4646
try:
47-
a_property_type0: Union[Unset, AnEnum]
47+
a_property_type_0: Union[Unset, AnEnum]
4848
if not isinstance(data, str):
4949
raise TypeError()
50-
a_property_type0 = UNSET
51-
_a_property_type0 = data
52-
if not isinstance(_a_property_type0, Unset):
53-
a_property_type0 = AnEnum(_a_property_type0)
50+
a_property_type_0 = UNSET
51+
_a_property_type_0 = data
52+
if not isinstance(_a_property_type_0, Unset):
53+
a_property_type_0 = AnEnum(_a_property_type_0)
5454

55-
return a_property_type0
55+
return a_property_type_0
5656
except: # noqa: E722
5757
pass
5858
if not isinstance(data, int):
5959
raise TypeError()
60-
a_property_type1: Union[Unset, AnIntEnum]
61-
a_property_type1 = UNSET
62-
_a_property_type1 = data
63-
if not isinstance(_a_property_type1, Unset):
64-
a_property_type1 = AnIntEnum(_a_property_type1)
60+
a_property_type_1: Union[Unset, AnIntEnum]
61+
a_property_type_1 = UNSET
62+
_a_property_type_1 = data
63+
if not isinstance(_a_property_type_1, Unset):
64+
a_property_type_1 = AnIntEnum(_a_property_type_1)
6565

66-
return a_property_type1
66+
return a_property_type_1
6767

6868
a_property = _parse_a_property(d.pop("a_property", UNSET))
6969

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import attr
44

5-
from ..models.model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0
6-
from ..models.model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1
5+
from ..models.model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
6+
from ..models.model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1
77
from ..types import UNSET, Unset
88

99
T = TypeVar("T", bound="ModelWithUnionPropertyInlined")
@@ -46,26 +46,26 @@ def _parse_fruit(
4646
if isinstance(data, Unset):
4747
return data
4848
try:
49-
fruit_type0: Union[Unset, ModelWithUnionPropertyInlinedFruitType0]
49+
fruit_type_0: Union[Unset, ModelWithUnionPropertyInlinedFruitType0]
5050
if not isinstance(data, dict):
5151
raise TypeError()
52-
fruit_type0 = UNSET
53-
_fruit_type0 = data
54-
if not isinstance(_fruit_type0, Unset):
55-
fruit_type0 = ModelWithUnionPropertyInlinedFruitType0.from_dict(_fruit_type0)
52+
fruit_type_0 = UNSET
53+
_fruit_type_0 = data
54+
if not isinstance(_fruit_type_0, Unset):
55+
fruit_type_0 = ModelWithUnionPropertyInlinedFruitType0.from_dict(_fruit_type_0)
5656

57-
return fruit_type0
57+
return fruit_type_0
5858
except: # noqa: E722
5959
pass
6060
if not isinstance(data, dict):
6161
raise TypeError()
62-
fruit_type1: Union[Unset, ModelWithUnionPropertyInlinedFruitType1]
63-
fruit_type1 = UNSET
64-
_fruit_type1 = data
65-
if not isinstance(_fruit_type1, Unset):
66-
fruit_type1 = ModelWithUnionPropertyInlinedFruitType1.from_dict(_fruit_type1)
62+
fruit_type_1: Union[Unset, ModelWithUnionPropertyInlinedFruitType1]
63+
fruit_type_1 = UNSET
64+
_fruit_type_1 = data
65+
if not isinstance(_fruit_type_1, Unset):
66+
fruit_type_1 = ModelWithUnionPropertyInlinedFruitType1.from_dict(_fruit_type_1)
6767

68-
return fruit_type1
68+
return fruit_type_1
6969

7070
fruit = _parse_fruit(d.pop("fruit", UNSET))
7171

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3030
d = src_dict.copy()
3131
apples = d.pop("apples", UNSET)
3232

33-
model_with_union_property_inlined_fruit_type0 = cls(
33+
model_with_union_property_inlined_fruit_type_0 = cls(
3434
apples=apples,
3535
)
3636

37-
model_with_union_property_inlined_fruit_type0.additional_properties = d
38-
return model_with_union_property_inlined_fruit_type0
37+
model_with_union_property_inlined_fruit_type_0.additional_properties = d
38+
return model_with_union_property_inlined_fruit_type_0
3939

4040
@property
4141
def additional_keys(self) -> List[str]:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3030
d = src_dict.copy()
3131
bananas = d.pop("bananas", UNSET)
3232

33-
model_with_union_property_inlined_fruit_type1 = cls(
33+
model_with_union_property_inlined_fruit_type_1 = cls(
3434
bananas=bananas,
3535
)
3636

37-
model_with_union_property_inlined_fruit_type1.additional_properties = d
38-
return model_with_union_property_inlined_fruit_type1
37+
model_with_union_property_inlined_fruit_type_1.additional_properties = d
38+
return model_with_union_property_inlined_fruit_type_1
3939

4040
@property
4141
def additional_keys(self) -> List[str]:

end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response200.py renamed to end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
2828
d = src_dict.copy()
2929
a_property = d.pop("a_property", UNSET)
3030

31-
test_inline_objects_response200 = cls(
31+
test_inline_objects_response_200 = cls(
3232
a_property=a_property,
3333
)
3434

35-
return test_inline_objects_response200
35+
return test_inline_objects_response_200

openapi_python_client/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def sanitize(value: str) -> str:
1313

1414
def split_words(value: str) -> List[str]:
1515
""" Split a string on non-capital letters and known delimiters """
16-
value = " ".join(re.split("([A-Z]?[a-z0-9]+)", value))
16+
value = " ".join(re.split("([A-Z]?[a-z]+)", value))
1717
return re.findall(rf"[^{delimiters}]+", value)
1818

1919

tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def test_snake_case_from_pascal_with_acronyms():
1515
assert utils.snake_case("S3Config") == "s3_config"
1616

1717

18+
def test_snake_case_from_pascal_with_numbers():
19+
assert utils.snake_case("Response200") == "response_200"
20+
assert utils.snake_case("Response200WithContent") == "response_200_with_content"
21+
22+
1823
def test_snake_case_from_pascal():
1924
assert utils.snake_case("HttpResponsePascalCase") == "http_response_pascal_case"
2025

0 commit comments

Comments
 (0)