Skip to content

Better naming of sub-model classes #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

Client = httpx.Client

from ...models.test_inline_objectsjson_body import TestInlineObjectsjsonBody
from ...models.test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200


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

return response_200
return None


def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsresponse_200]:
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse_200]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -30,8 +30,8 @@ def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsre
def httpx_request(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
) -> Response[TestInlineObjectsresponse_200]:
json_body: TestInlineObjectsJsonBody,
) -> Response[TestInlineObjectsResponse_200]:

json_json_body = json_body.to_dict()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
from .different_enum import DifferentEnum
from .http_validation_error import HTTPValidationError
from .model_with_union_property import ModelWithUnionProperty
from .test_inline_objectsjson_body import TestInlineObjectsjsonBody
from .test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200
from .validation_error import ValidationError
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@attr.s(auto_attribs=True)
class TestInlineObjectsjsonBody:
class TestInlineObjectsJsonBody:
""" """

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

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

return TestInlineObjectsjsonBody(
return TestInlineObjectsJsonBody(
a_property=a_property,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@attr.s(auto_attribs=True)
class TestInlineObjectsresponse_200:
class TestInlineObjectsResponse_200:
""" """

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

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

return TestInlineObjectsresponse_200(
return TestInlineObjectsResponse_200(
a_property=a_property,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import httpx

from ...client import Client
from ...models.test_inline_objectsjson_body import TestInlineObjectsjsonBody
from ...models.test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody
from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200
from ...types import Response


def _get_kwargs(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
json_body: TestInlineObjectsJsonBody,
) -> Dict[str, Any]:
url = "{}/tests/inline_objects".format(client.base_url)

Expand All @@ -28,15 +28,15 @@ def _get_kwargs(
}


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

return response_200
return None


def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsresponse_200]:
def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse_200]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -48,8 +48,8 @@ def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsre
def sync_detailed(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
) -> Response[TestInlineObjectsresponse_200]:
json_body: TestInlineObjectsJsonBody,
) -> Response[TestInlineObjectsResponse_200]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
Expand All @@ -65,8 +65,8 @@ def sync_detailed(
def sync(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
) -> Optional[TestInlineObjectsresponse_200]:
json_body: TestInlineObjectsJsonBody,
) -> Optional[TestInlineObjectsResponse_200]:
""" """

return sync_detailed(
Expand All @@ -78,8 +78,8 @@ def sync(
async def asyncio_detailed(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
) -> Response[TestInlineObjectsresponse_200]:
json_body: TestInlineObjectsJsonBody,
) -> Response[TestInlineObjectsResponse_200]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
Expand All @@ -94,8 +94,8 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Client,
json_body: TestInlineObjectsjsonBody,
) -> Optional[TestInlineObjectsresponse_200]:
json_body: TestInlineObjectsJsonBody,
) -> Optional[TestInlineObjectsResponse_200]:
""" """

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
from .different_enum import DifferentEnum
from .http_validation_error import HTTPValidationError
from .model_with_union_property import ModelWithUnionProperty
from .test_inline_objectsjson_body import TestInlineObjectsjsonBody
from .test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
from .test_inline_objects_response_200 import TestInlineObjectsResponse_200
from .validation_error import ValidationError
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@attr.s(auto_attribs=True)
class TestInlineObjectsjsonBody:
class TestInlineObjectsJsonBody:
""" """

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

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

return TestInlineObjectsjsonBody(
return TestInlineObjectsJsonBody(
a_property=a_property,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@attr.s(auto_attribs=True)
class TestInlineObjectsresponse_200:
class TestInlineObjectsResponse_200:
""" """

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

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

return TestInlineObjectsresponse_200(
return TestInlineObjectsResponse_200(
a_property=a_property,
)
6 changes: 3 additions & 3 deletions openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def build_model_property(

class_name = data.title or name
if parent_name:
class_name = f"{utils.pascal_case(parent_name)}{class_name}"
class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}"
ref = Reference.from_ref(class_name)

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

class_name = data.title or name
if parent_name:
class_name = f"{utils.pascal_case(parent_name)}{class_name}"
class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}"
reference = Reference.from_ref(class_name)
values = EnumProperty.values_from_list(enum)

Expand Down Expand Up @@ -373,7 +373,7 @@ def build_list_property(
if data.items is None:
return PropertyError(data=data, detail="type array must have items defined"), schemas
inner_prop, schemas = property_from_data(
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=f"{parent_name}_{name}"
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=parent_name
)
if isinstance(inner_prop, PropertyError):
return PropertyError(data=inner_prop.data, detail=f"invalid data in items of array {name}"), schemas
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parser/test_properties/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_property_from_data_int_enum(self, mocker):
from openapi_python_client.parser.properties import EnumProperty, Reference
from openapi_python_client.schema import Schema

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

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

def test_build_list_property(self, mocker):
Expand Down Expand Up @@ -849,7 +849,7 @@ def test_build_list_property(self, mocker):
assert new_schemas == second_schemas
assert schemas != new_schemas, "Schema was mutated"
property_from_data.assert_called_once_with(
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent_prop"
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name="parent"
)


Expand Down