Skip to content

Commit 85a070a

Browse files
ramnesdbanty
andauthored
fix!: Some generated names will be different, solving some inconsistencies. (closes #369) (#375) Thanks @ramnes!
* Don't depend on stringcase (closes #369) Let's reimplement what we need here so that we don't depend on stringcase anymore (see #369 for rationale). I've added a few test cases for stuff I've seen break along the way. * refactor: Fix unit test to match new behavior, optimize word capitalization. * test: Regen golden-record * fix(cases): treat numbers as words when processing cases Co-authored-by: Dylan Anthony <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
1 parent 83a360f commit 85a070a

16 files changed

+135
-166
lines changed

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py

+8-8
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_response_200 import TestInlineObjectsResponse_200
7+
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200
88
from ...types import Response
99

1010

@@ -29,15 +29,15 @@ def _get_kwargs(
2929
}
3030

3131

32-
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse_200]:
32+
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse200]:
3333
if response.status_code == 200:
34-
response_200 = TestInlineObjectsResponse_200.from_dict(response.json())
34+
response_200 = TestInlineObjectsResponse200.from_dict(response.json())
3535

3636
return response_200
3737
return None
3838

3939

40-
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse_200]:
40+
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse200]:
4141
return Response(
4242
status_code=response.status_code,
4343
content=response.content,
@@ -50,7 +50,7 @@ def sync_detailed(
5050
*,
5151
client: Client,
5252
json_body: TestInlineObjectsJsonBody,
53-
) -> Response[TestInlineObjectsResponse_200]:
53+
) -> Response[TestInlineObjectsResponse200]:
5454
kwargs = _get_kwargs(
5555
client=client,
5656
json_body=json_body,
@@ -67,7 +67,7 @@ def sync(
6767
*,
6868
client: Client,
6969
json_body: TestInlineObjectsJsonBody,
70-
) -> Optional[TestInlineObjectsResponse_200]:
70+
) -> Optional[TestInlineObjectsResponse200]:
7171
""" """
7272

7373
return sync_detailed(
@@ -80,7 +80,7 @@ async def asyncio_detailed(
8080
*,
8181
client: Client,
8282
json_body: TestInlineObjectsJsonBody,
83-
) -> Response[TestInlineObjectsResponse_200]:
83+
) -> Response[TestInlineObjectsResponse200]:
8484
kwargs = _get_kwargs(
8585
client=client,
8686
json_body=json_body,
@@ -96,7 +96,7 @@ async def asyncio(
9696
*,
9797
client: Client,
9898
json_body: TestInlineObjectsJsonBody,
99-
) -> Optional[TestInlineObjectsResponse_200]:
99+
) -> Optional[TestInlineObjectsResponse200]:
100100
""" """
101101

102102
return (

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/__init__.py

+4-4
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_response_200 import TestInlineObjectsResponse_200
30+
from .test_inline_objects_response_200 import TestInlineObjectsResponse200
3131
from .validation_error import ValidationError

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/a_model.py

+44-44
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)

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py

+7-7
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(

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type0.py renamed to end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py

+3-3
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]:

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py

+12-12
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

Diff for: end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py

+14-14
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

0 commit comments

Comments
 (0)