Skip to content

Commit 802557a

Browse files
authored
Better naming of sub-model classes (#250)
* Fix capitalization of models * Don't double specify name in list props
1 parent 5cfcb0f commit 802557a

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/test_inline_objects.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
Client = httpx.Client
88

9-
from ...models.test_inline_objectsjson_body import TestInlineObjectsjsonBody
10-
from ...models.test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
9+
from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody
10+
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200
1111

1212

13-
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsresponse_200]:
13+
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse_200]:
1414
if response.status_code == 200:
15-
response_200 = TestInlineObjectsresponse_200.from_dict(response.json())
15+
response_200 = TestInlineObjectsResponse_200.from_dict(response.json())
1616

1717
return response_200
1818
return None
1919

2020

21-
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsresponse_200]:
21+
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse_200]:
2222
return Response(
2323
status_code=response.status_code,
2424
content=response.content,
@@ -30,8 +30,8 @@ def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsre
3030
def httpx_request(
3131
*,
3232
client: Client,
33-
json_body: TestInlineObjectsjsonBody,
34-
) -> Response[TestInlineObjectsresponse_200]:
33+
json_body: TestInlineObjectsJsonBody,
34+
) -> Response[TestInlineObjectsResponse_200]:
3535

3636
json_json_body = json_body.to_dict()
3737

end_to_end_tests/golden-record-custom/custom_e2e/models/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
from .different_enum import DifferentEnum
88
from .http_validation_error import HTTPValidationError
99
from .model_with_union_property import ModelWithUnionProperty
10-
from .test_inline_objectsjson_body import TestInlineObjectsjsonBody
11-
from .test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
10+
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
11+
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200
1212
from .validation_error import ValidationError

end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objectsjson_body.py renamed to end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_json_body.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@attr.s(auto_attribs=True)
9-
class TestInlineObjectsjsonBody:
9+
class TestInlineObjectsJsonBody:
1010
""" """
1111

1212
a_property: Union[Unset, str] = UNSET
@@ -21,9 +21,9 @@ def to_dict(self) -> Dict[str, Any]:
2121
return field_dict
2222

2323
@staticmethod
24-
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsjsonBody":
24+
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsJsonBody":
2525
a_property = d.get("a_property", UNSET)
2626

27-
return TestInlineObjectsjsonBody(
27+
return TestInlineObjectsJsonBody(
2828
a_property=a_property,
2929
)

end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objectsresponse_200.py renamed to end_to_end_tests/golden-record-custom/custom_e2e/models/test_inline_objects_response_200.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@attr.s(auto_attribs=True)
9-
class TestInlineObjectsresponse_200:
9+
class TestInlineObjectsResponse_200:
1010
""" """
1111

1212
a_property: Union[Unset, str] = UNSET
@@ -21,9 +21,9 @@ def to_dict(self) -> Dict[str, Any]:
2121
return field_dict
2222

2323
@staticmethod
24-
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsresponse_200":
24+
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsResponse_200":
2525
a_property = d.get("a_property", UNSET)
2626

27-
return TestInlineObjectsresponse_200(
27+
return TestInlineObjectsResponse_200(
2828
a_property=a_property,
2929
)

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import httpx
44

55
from ...client import Client
6-
from ...models.test_inline_objectsjson_body import TestInlineObjectsjsonBody
7-
from ...models.test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
6+
from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody
7+
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200
88
from ...types import Response
99

1010

1111
def _get_kwargs(
1212
*,
1313
client: Client,
14-
json_body: TestInlineObjectsjsonBody,
14+
json_body: TestInlineObjectsJsonBody,
1515
) -> Dict[str, Any]:
1616
url = "{}/tests/inline_objects".format(client.base_url)
1717

@@ -28,15 +28,15 @@ def _get_kwargs(
2828
}
2929

3030

31-
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsresponse_200]:
31+
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse_200]:
3232
if response.status_code == 200:
33-
response_200 = TestInlineObjectsresponse_200.from_dict(response.json())
33+
response_200 = TestInlineObjectsResponse_200.from_dict(response.json())
3434

3535
return response_200
3636
return None
3737

3838

39-
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsresponse_200]:
39+
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse_200]:
4040
return Response(
4141
status_code=response.status_code,
4242
content=response.content,
@@ -48,8 +48,8 @@ def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsre
4848
def sync_detailed(
4949
*,
5050
client: Client,
51-
json_body: TestInlineObjectsjsonBody,
52-
) -> Response[TestInlineObjectsresponse_200]:
51+
json_body: TestInlineObjectsJsonBody,
52+
) -> Response[TestInlineObjectsResponse_200]:
5353
kwargs = _get_kwargs(
5454
client=client,
5555
json_body=json_body,
@@ -65,8 +65,8 @@ def sync_detailed(
6565
def sync(
6666
*,
6767
client: Client,
68-
json_body: TestInlineObjectsjsonBody,
69-
) -> Optional[TestInlineObjectsresponse_200]:
68+
json_body: TestInlineObjectsJsonBody,
69+
) -> Optional[TestInlineObjectsResponse_200]:
7070
""" """
7171

7272
return sync_detailed(
@@ -78,8 +78,8 @@ def sync(
7878
async def asyncio_detailed(
7979
*,
8080
client: Client,
81-
json_body: TestInlineObjectsjsonBody,
82-
) -> Response[TestInlineObjectsresponse_200]:
81+
json_body: TestInlineObjectsJsonBody,
82+
) -> Response[TestInlineObjectsResponse_200]:
8383
kwargs = _get_kwargs(
8484
client=client,
8585
json_body=json_body,
@@ -94,8 +94,8 @@ async def asyncio_detailed(
9494
async def asyncio(
9595
*,
9696
client: Client,
97-
json_body: TestInlineObjectsjsonBody,
98-
) -> Optional[TestInlineObjectsresponse_200]:
97+
json_body: TestInlineObjectsJsonBody,
98+
) -> Optional[TestInlineObjectsResponse_200]:
9999
""" """
100100

101101
return (

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
from .different_enum import DifferentEnum
88
from .http_validation_error import HTTPValidationError
99
from .model_with_union_property import ModelWithUnionProperty
10-
from .test_inline_objectsjson_body import TestInlineObjectsjsonBody
11-
from .test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
10+
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
11+
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200
1212
from .validation_error import ValidationError

end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objectsjson_body.py renamed to end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@attr.s(auto_attribs=True)
9-
class TestInlineObjectsjsonBody:
9+
class TestInlineObjectsJsonBody:
1010
""" """
1111

1212
a_property: Union[Unset, str] = UNSET
@@ -21,9 +21,9 @@ def to_dict(self) -> Dict[str, Any]:
2121
return field_dict
2222

2323
@staticmethod
24-
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsjsonBody":
24+
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsJsonBody":
2525
a_property = d.get("a_property", UNSET)
2626

27-
return TestInlineObjectsjsonBody(
27+
return TestInlineObjectsJsonBody(
2828
a_property=a_property,
2929
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@attr.s(auto_attribs=True)
9-
class TestInlineObjectsresponse_200:
9+
class TestInlineObjectsResponse_200:
1010
""" """
1111

1212
a_property: Union[Unset, str] = UNSET
@@ -21,9 +21,9 @@ def to_dict(self) -> Dict[str, Any]:
2121
return field_dict
2222

2323
@staticmethod
24-
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsresponse_200":
24+
def from_dict(d: Dict[str, Any]) -> "TestInlineObjectsResponse_200":
2525
a_property = d.get("a_property", UNSET)
2626

27-
return TestInlineObjectsresponse_200(
27+
return TestInlineObjectsResponse_200(
2828
a_property=a_property,
2929
)

openapi_python_client/parser/properties/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def build_model_property(
239239

240240
class_name = data.title or name
241241
if parent_name:
242-
class_name = f"{utils.pascal_case(parent_name)}{class_name}"
242+
class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}"
243243
ref = Reference.from_ref(class_name)
244244

245245
for key, value in (data.properties or {}).items():
@@ -296,7 +296,7 @@ def build_enum_property(
296296

297297
class_name = data.title or name
298298
if parent_name:
299-
class_name = f"{utils.pascal_case(parent_name)}{class_name}"
299+
class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}"
300300
reference = Reference.from_ref(class_name)
301301
values = EnumProperty.values_from_list(enum)
302302

@@ -373,7 +373,7 @@ def build_list_property(
373373
if data.items is None:
374374
return PropertyError(data=data, detail="type array must have items defined"), schemas
375375
inner_prop, schemas = property_from_data(
376-
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=f"{parent_name}_{name}"
376+
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=parent_name
377377
)
378378
if isinstance(inner_prop, PropertyError):
379379
return PropertyError(data=inner_prop.data, detail=f"invalid data in items of array {name}"), schemas

tests/test_parser/test_properties/test_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def test_property_from_data_int_enum(self, mocker):
515515
from openapi_python_client.parser.properties import EnumProperty, Reference
516516
from openapi_python_client.schema import Schema
517517

518-
data = Schema.construct(title="AnEnum", enum=[1, 2, 3], nullable=False, default=3)
518+
data = Schema.construct(title="anEnum", enum=[1, 2, 3], nullable=False, default=3)
519519
name = "my_enum"
520520
required = True
521521

@@ -820,7 +820,7 @@ def test_build_list_property_invalid_items(self, mocker):
820820
assert new_schemas == second_schemas
821821
assert schemas != new_schemas, "Schema was mutated"
822822
property_from_data.assert_called_once_with(
823-
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent_name"
823+
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent"
824824
)
825825

826826
def test_build_list_property(self, mocker):
@@ -849,7 +849,7 @@ def test_build_list_property(self, mocker):
849849
assert new_schemas == second_schemas
850850
assert schemas != new_schemas, "Schema was mutated"
851851
property_from_data.assert_called_once_with(
852-
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent_prop"
852+
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent"
853853
)
854854

855855

0 commit comments

Comments
 (0)