diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index 8680e8ef8..04fc372c4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -4,7 +4,7 @@ from ...client import Client from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody -from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse_200 +from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200 from ...types import Response @@ -29,15 +29,15 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse_200]: +def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse200]: if response.status_code == 200: - response_200 = TestInlineObjectsResponse_200.from_dict(response.json()) + response_200 = TestInlineObjectsResponse200.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[TestInlineObjectsResponse200]: return Response( status_code=response.status_code, content=response.content, @@ -50,7 +50,7 @@ def sync_detailed( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Response[TestInlineObjectsResponse_200]: +) -> Response[TestInlineObjectsResponse200]: kwargs = _get_kwargs( client=client, json_body=json_body, @@ -67,7 +67,7 @@ def sync( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse_200]: +) -> Optional[TestInlineObjectsResponse200]: """ """ return sync_detailed( @@ -80,7 +80,7 @@ async def asyncio_detailed( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Response[TestInlineObjectsResponse_200]: +) -> Response[TestInlineObjectsResponse200]: kwargs = _get_kwargs( client=client, json_body=json_body, @@ -96,7 +96,7 @@ async def asyncio( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse_200]: +) -> Optional[TestInlineObjectsResponse200]: """ """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py index 93c6bab3a..5bbd77d7d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py @@ -18,14 +18,14 @@ ) from .model_with_additional_properties_refed import ModelWithAdditionalPropertiesRefed from .model_with_any_json_properties import ModelWithAnyJsonProperties -from .model_with_any_json_properties_additional_property_type0 import ModelWithAnyJsonPropertiesAdditionalPropertyType0 +from .model_with_any_json_properties_additional_property_type_0 import ModelWithAnyJsonPropertiesAdditionalPropertyType0 from .model_with_primitive_additional_properties import ModelWithPrimitiveAdditionalProperties from .model_with_primitive_additional_properties_a_date_holder import ModelWithPrimitiveAdditionalPropertiesADateHolder from .model_with_property_ref import ModelWithPropertyRef from .model_with_union_property import ModelWithUnionProperty from .model_with_union_property_inlined import ModelWithUnionPropertyInlined -from .model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0 -from .model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1 +from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 +from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 from .test_inline_objects_json_body import TestInlineObjectsJsonBody -from .test_inline_objects_response_200 import TestInlineObjectsResponse_200 +from .test_inline_objects_response_200 import TestInlineObjectsResponse200 from .validation_error import ValidationError diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index ea60401c4..c058bf291 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -186,20 +186,20 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.datetime]: try: - a_camel_date_time_type0: datetime.datetime + a_camel_date_time_type_0: datetime.datetime if not isinstance(data, str): raise TypeError() - a_camel_date_time_type0 = isoparse(data) + a_camel_date_time_type_0 = isoparse(data) - return a_camel_date_time_type0 + return a_camel_date_time_type_0 except: # noqa: E722 pass if not isinstance(data, str): raise TypeError() - a_camel_date_time_type1: datetime.date - a_camel_date_time_type1 = isoparse(data).date() + a_camel_date_time_type_1: datetime.date + a_camel_date_time_type_1 = isoparse(data).date() - return a_camel_date_time_type1 + return a_camel_date_time_type_1 a_camel_date_time = _parse_a_camel_date_time(d.pop("aCamelDateTime")) @@ -209,20 +209,20 @@ def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.date def _parse_one_of_models(data: object) -> Union[FreeFormModel, ModelWithUnionProperty]: try: - one_of_models_type0: FreeFormModel + one_of_models_type_0: FreeFormModel if not isinstance(data, dict): raise TypeError() - one_of_models_type0 = FreeFormModel.from_dict(data) + one_of_models_type_0 = FreeFormModel.from_dict(data) - return one_of_models_type0 + return one_of_models_type_0 except: # noqa: E722 pass if not isinstance(data, dict): raise TypeError() - one_of_models_type1: ModelWithUnionProperty - one_of_models_type1 = ModelWithUnionProperty.from_dict(data) + one_of_models_type_1: ModelWithUnionProperty + one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) - return one_of_models_type1 + return one_of_models_type_1 one_of_models = _parse_one_of_models(d.pop("one_of_models")) @@ -267,20 +267,20 @@ def _parse_nullable_one_of_models(data: object) -> Union[FreeFormModel, ModelWit if data is None: return data try: - nullable_one_of_models_type0: FreeFormModel + nullable_one_of_models_type_0: FreeFormModel if not isinstance(data, dict): raise TypeError() - nullable_one_of_models_type0 = FreeFormModel.from_dict(data) + nullable_one_of_models_type_0 = FreeFormModel.from_dict(data) - return nullable_one_of_models_type0 + return nullable_one_of_models_type_0 except: # noqa: E722 pass if not isinstance(data, dict): raise TypeError() - nullable_one_of_models_type1: ModelWithUnionProperty - nullable_one_of_models_type1 = ModelWithUnionProperty.from_dict(data) + nullable_one_of_models_type_1: ModelWithUnionProperty + nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) - return nullable_one_of_models_type1 + return nullable_one_of_models_type_1 nullable_one_of_models = _parse_nullable_one_of_models(d.pop("nullable_one_of_models")) @@ -288,26 +288,26 @@ def _parse_not_required_one_of_models(data: object) -> Union[FreeFormModel, Mode if isinstance(data, Unset): return data try: - not_required_one_of_models_type0: Union[Unset, FreeFormModel] + not_required_one_of_models_type_0: Union[Unset, FreeFormModel] if not isinstance(data, dict): raise TypeError() - not_required_one_of_models_type0 = UNSET - _not_required_one_of_models_type0 = data - if not isinstance(_not_required_one_of_models_type0, Unset): - not_required_one_of_models_type0 = FreeFormModel.from_dict(_not_required_one_of_models_type0) + not_required_one_of_models_type_0 = UNSET + _not_required_one_of_models_type_0 = data + if not isinstance(_not_required_one_of_models_type_0, Unset): + not_required_one_of_models_type_0 = FreeFormModel.from_dict(_not_required_one_of_models_type_0) - return not_required_one_of_models_type0 + return not_required_one_of_models_type_0 except: # noqa: E722 pass if not isinstance(data, dict): raise TypeError() - not_required_one_of_models_type1: Union[Unset, ModelWithUnionProperty] - not_required_one_of_models_type1 = UNSET - _not_required_one_of_models_type1 = data - if not isinstance(_not_required_one_of_models_type1, Unset): - not_required_one_of_models_type1 = ModelWithUnionProperty.from_dict(_not_required_one_of_models_type1) + not_required_one_of_models_type_1: Union[Unset, ModelWithUnionProperty] + not_required_one_of_models_type_1 = UNSET + _not_required_one_of_models_type_1 = data + if not isinstance(_not_required_one_of_models_type_1, Unset): + not_required_one_of_models_type_1 = ModelWithUnionProperty.from_dict(_not_required_one_of_models_type_1) - return not_required_one_of_models_type1 + return not_required_one_of_models_type_1 not_required_one_of_models = _parse_not_required_one_of_models(d.pop("not_required_one_of_models", UNSET)) @@ -319,31 +319,31 @@ def _parse_not_required_nullable_one_of_models( if isinstance(data, Unset): return data try: - not_required_nullable_one_of_models_type0: Union[Unset, FreeFormModel] + not_required_nullable_one_of_models_type_0: Union[Unset, FreeFormModel] if not isinstance(data, dict): raise TypeError() - not_required_nullable_one_of_models_type0 = UNSET - _not_required_nullable_one_of_models_type0 = data - if not isinstance(_not_required_nullable_one_of_models_type0, Unset): - not_required_nullable_one_of_models_type0 = FreeFormModel.from_dict( - _not_required_nullable_one_of_models_type0 + not_required_nullable_one_of_models_type_0 = UNSET + _not_required_nullable_one_of_models_type_0 = data + if not isinstance(_not_required_nullable_one_of_models_type_0, Unset): + not_required_nullable_one_of_models_type_0 = FreeFormModel.from_dict( + _not_required_nullable_one_of_models_type_0 ) - return not_required_nullable_one_of_models_type0 + return not_required_nullable_one_of_models_type_0 except: # noqa: E722 pass try: - not_required_nullable_one_of_models_type1: Union[Unset, ModelWithUnionProperty] + not_required_nullable_one_of_models_type_1: Union[Unset, ModelWithUnionProperty] if not isinstance(data, dict): raise TypeError() - not_required_nullable_one_of_models_type1 = UNSET - _not_required_nullable_one_of_models_type1 = data - if not isinstance(_not_required_nullable_one_of_models_type1, Unset): - not_required_nullable_one_of_models_type1 = ModelWithUnionProperty.from_dict( - _not_required_nullable_one_of_models_type1 + not_required_nullable_one_of_models_type_1 = UNSET + _not_required_nullable_one_of_models_type_1 = data + if not isinstance(_not_required_nullable_one_of_models_type_1, Unset): + not_required_nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict( + _not_required_nullable_one_of_models_type_1 ) - return not_required_nullable_one_of_models_type1 + return not_required_nullable_one_of_models_type_1 except: # noqa: E722 pass return cast(Union[FreeFormModel, ModelWithUnionProperty, None, Unset, str], data) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py index 59b3ddb46..9b22f9154 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py @@ -2,7 +2,7 @@ import attr -from ..models.model_with_any_json_properties_additional_property_type0 import ( +from ..models.model_with_any_json_properties_additional_property_type_0 import ( ModelWithAnyJsonPropertiesAdditionalPropertyType0, ) @@ -46,21 +46,21 @@ def _parse_additional_property( data: object, ) -> Union[List[str], ModelWithAnyJsonPropertiesAdditionalPropertyType0, bool, float, int, str]: try: - additional_property_type0: ModelWithAnyJsonPropertiesAdditionalPropertyType0 + additional_property_type_0: ModelWithAnyJsonPropertiesAdditionalPropertyType0 if not isinstance(data, dict): raise TypeError() - additional_property_type0 = ModelWithAnyJsonPropertiesAdditionalPropertyType0.from_dict(data) + additional_property_type_0 = ModelWithAnyJsonPropertiesAdditionalPropertyType0.from_dict(data) - return additional_property_type0 + return additional_property_type_0 except: # noqa: E722 pass try: - additional_property_type1: List[str] + additional_property_type_1: List[str] if not isinstance(data, list): raise TypeError() - additional_property_type1 = cast(List[str], data) + additional_property_type_1 = cast(List[str], data) - return additional_property_type1 + return additional_property_type_1 except: # noqa: E722 pass return cast( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py similarity index 87% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type0.py rename to end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py index 76649bf90..5d271b266 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py @@ -22,10 +22,10 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_any_json_properties_additional_property_type0 = cls() + model_with_any_json_properties_additional_property_type_0 = cls() - model_with_any_json_properties_additional_property_type0.additional_properties = d - return model_with_any_json_properties_additional_property_type0 + model_with_any_json_properties_additional_property_type_0.additional_properties = d + return model_with_any_json_properties_additional_property_type_0 @property def additional_keys(self) -> List[str]: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py index a3f049533..5981b8c74 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py @@ -44,26 +44,26 @@ def _parse_a_property(data: object) -> Union[AnEnum, AnIntEnum, Unset]: if isinstance(data, Unset): return data try: - a_property_type0: Union[Unset, AnEnum] + a_property_type_0: Union[Unset, AnEnum] if not isinstance(data, str): raise TypeError() - a_property_type0 = UNSET - _a_property_type0 = data - if not isinstance(_a_property_type0, Unset): - a_property_type0 = AnEnum(_a_property_type0) + a_property_type_0 = UNSET + _a_property_type_0 = data + if not isinstance(_a_property_type_0, Unset): + a_property_type_0 = AnEnum(_a_property_type_0) - return a_property_type0 + return a_property_type_0 except: # noqa: E722 pass if not isinstance(data, int): raise TypeError() - a_property_type1: Union[Unset, AnIntEnum] - a_property_type1 = UNSET - _a_property_type1 = data - if not isinstance(_a_property_type1, Unset): - a_property_type1 = AnIntEnum(_a_property_type1) + a_property_type_1: Union[Unset, AnIntEnum] + a_property_type_1 = UNSET + _a_property_type_1 = data + if not isinstance(_a_property_type_1, Unset): + a_property_type_1 = AnIntEnum(_a_property_type_1) - return a_property_type1 + return a_property_type_1 a_property = _parse_a_property(d.pop("a_property", UNSET)) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py index 2349d541d..a9607f999 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py @@ -2,8 +2,8 @@ import attr -from ..models.model_with_union_property_inlined_fruit_type0 import ModelWithUnionPropertyInlinedFruitType0 -from ..models.model_with_union_property_inlined_fruit_type1 import ModelWithUnionPropertyInlinedFruitType1 +from ..models.model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 +from ..models.model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 from ..types import UNSET, Unset T = TypeVar("T", bound="ModelWithUnionPropertyInlined") @@ -46,26 +46,26 @@ def _parse_fruit( if isinstance(data, Unset): return data try: - fruit_type0: Union[Unset, ModelWithUnionPropertyInlinedFruitType0] + fruit_type_0: Union[Unset, ModelWithUnionPropertyInlinedFruitType0] if not isinstance(data, dict): raise TypeError() - fruit_type0 = UNSET - _fruit_type0 = data - if not isinstance(_fruit_type0, Unset): - fruit_type0 = ModelWithUnionPropertyInlinedFruitType0.from_dict(_fruit_type0) + fruit_type_0 = UNSET + _fruit_type_0 = data + if not isinstance(_fruit_type_0, Unset): + fruit_type_0 = ModelWithUnionPropertyInlinedFruitType0.from_dict(_fruit_type_0) - return fruit_type0 + return fruit_type_0 except: # noqa: E722 pass if not isinstance(data, dict): raise TypeError() - fruit_type1: Union[Unset, ModelWithUnionPropertyInlinedFruitType1] - fruit_type1 = UNSET - _fruit_type1 = data - if not isinstance(_fruit_type1, Unset): - fruit_type1 = ModelWithUnionPropertyInlinedFruitType1.from_dict(_fruit_type1) + fruit_type_1: Union[Unset, ModelWithUnionPropertyInlinedFruitType1] + fruit_type_1 = UNSET + _fruit_type_1 = data + if not isinstance(_fruit_type_1, Unset): + fruit_type_1 = ModelWithUnionPropertyInlinedFruitType1.from_dict(_fruit_type_1) - return fruit_type1 + return fruit_type_1 fruit = _parse_fruit(d.pop("fruit", UNSET)) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py similarity index 86% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type0.py rename to end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py index da6d11826..8a8739465 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py @@ -30,12 +30,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() apples = d.pop("apples", UNSET) - model_with_union_property_inlined_fruit_type0 = cls( + model_with_union_property_inlined_fruit_type_0 = cls( apples=apples, ) - model_with_union_property_inlined_fruit_type0.additional_properties = d - return model_with_union_property_inlined_fruit_type0 + model_with_union_property_inlined_fruit_type_0.additional_properties = d + return model_with_union_property_inlined_fruit_type_0 @property def additional_keys(self) -> List[str]: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type1.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py similarity index 86% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type1.py rename to end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py index 32a9b1727..7b1792f5e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type1.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py @@ -30,12 +30,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() bananas = d.pop("bananas", UNSET) - model_with_union_property_inlined_fruit_type1 = cls( + model_with_union_property_inlined_fruit_type_1 = cls( bananas=bananas, ) - model_with_union_property_inlined_fruit_type1.additional_properties = d - return model_with_union_property_inlined_fruit_type1 + model_with_union_property_inlined_fruit_type_1.additional_properties = d + return model_with_union_property_inlined_fruit_type_1 @property def additional_keys(self) -> List[str]: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py index 6e44a5b14..9b1a6fa58 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py @@ -4,11 +4,11 @@ from ..types import UNSET, Unset -T = TypeVar("T", bound="TestInlineObjectsResponse_200") +T = TypeVar("T", bound="TestInlineObjectsResponse200") @attr.s(auto_attribs=True) -class TestInlineObjectsResponse_200: +class TestInlineObjectsResponse200: """ """ a_property: Union[Unset, str] = UNSET diff --git a/mypy.ini b/mypy.ini index b37bb1eb0..1d3e58607 100644 --- a/mypy.ini +++ b/mypy.ini @@ -8,9 +8,6 @@ strict_equality = True [mypy-importlib_metadata] ignore_missing_imports = True -[mypy-stringcase] -ignore_missing_imports = True - [mypy-typer] ignore_missing_imports = True diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py index 6cdcb2119..25f138924 100644 --- a/openapi_python_client/utils.py +++ b/openapi_python_client/utils.py @@ -1,13 +1,20 @@ import builtins import re from keyword import iskeyword +from typing import List -import stringcase +delimiters = " _-" def sanitize(value: str) -> str: - """ Removes every character that isn't 0-9, A-Z, a-z, ' ', -, or _ """ - return re.sub(r"[^\w _\-]+", "", value) + """ Removes every character that isn't 0-9, A-Z, a-z, or a known delimiter """ + return re.sub(rf"[^\w{delimiters}]+", "", value) + + +def split_words(value: str) -> List[str]: + """ Split a string on non-capital letters and known delimiters """ + value = " ".join(re.split("([A-Z]?[a-z]+)", value)) + return re.findall(rf"[^{delimiters}]+", value) def fix_keywords(value: str) -> str: @@ -25,22 +32,23 @@ def fix_reserved_words(value: str) -> str: return value -def group_title(value: str) -> str: - value = re.sub(r"([A-Z]{2,})([A-Z][a-z]|[ \-_]|$)", lambda m: m.group(1).title() + m.group(2), value.strip()) - value = re.sub(r"(^|[ _-])([A-Z])", lambda m: m.group(1) + m.group(2).lower(), value) - return value - - def snake_case(value: str) -> str: - return fix_keywords(stringcase.snakecase(group_title(sanitize(value)))) + words = split_words(sanitize(value)) + value = "_".join(words).lower() + return fix_keywords(value) def pascal_case(value: str) -> str: - return fix_keywords(stringcase.pascalcase(sanitize(value.replace(" ", "")))) + words = split_words(sanitize(value)) + capitalized_words = (word.capitalize() if not word.isupper() else word for word in words) + value = "".join(capitalized_words) + return fix_keywords(value) def kebab_case(value: str) -> str: - return fix_keywords(stringcase.spinalcase(group_title(sanitize(value)))) + words = split_words(sanitize(value)) + value = "-".join(words).lower() + return fix_keywords(value) def remove_string_escapes(value: str) -> str: diff --git a/poetry.lock b/poetry.lock index 857878324..3a5c0b0c3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -564,14 +564,6 @@ python-versions = ">=3.5" [package.dependencies] contextvars = {version = ">=2.1", markers = "python_version < \"3.7\""} -[[package]] -name = "stringcase" -version = "1.2.0" -description = "String case converter." -category = "main" -optional = false -python-versions = "*" - [[package]] name = "taskipy" version = "1.7.0" @@ -668,7 +660,7 @@ testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake [metadata] lock-version = "1.1" python-versions = "^3.6" -content-hash = "192ab706eb92d4283c09160f994d21d176d1ba3b70e878ac81b7f94450682e0a" +content-hash = "ecb9809f99089aae2ff5bc8532402c5a5abae87a7dfaedbfca5daa505744eedd" [metadata.files] appdirs = [ @@ -687,6 +679,7 @@ autoflake = [ {file = "autoflake-1.4.tar.gz", hash = "sha256:61a353012cff6ab94ca062823d1fb2f692c4acda51c76ff83a8d77915fba51ea"}, ] black = [ + {file = "black-20.8b1-py3-none-any.whl", hash = "sha256:70b62ef1527c950db59062cda342ea224d772abdf6adc58b86a45421bab20a6b"}, {file = "black-20.8b1.tar.gz", hash = "sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea"}, ] certifi = [ @@ -821,39 +814,20 @@ markupsafe = [ {file = "MarkupSafe-1.1.1-cp35-cp35m-win32.whl", hash = "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1"}, {file = "MarkupSafe-1.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-win32.whl", hash = "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66"}, {file = "MarkupSafe-1.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"}, {file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"}, {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"}, {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b"}, {file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"}, {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-win32.whl", hash = "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8"}, {file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"}, ] mccabe = [ @@ -1028,12 +1002,6 @@ regex = [ {file = "regex-2020.9.27-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:8d69cef61fa50c8133382e61fd97439de1ae623fe943578e477e76a9d9471637"}, {file = "regex-2020.9.27-cp38-cp38-win32.whl", hash = "sha256:f2388013e68e750eaa16ccbea62d4130180c26abb1d8e5d584b9baf69672b30f"}, {file = "regex-2020.9.27-cp38-cp38-win_amd64.whl", hash = "sha256:4318d56bccfe7d43e5addb272406ade7a2274da4b70eb15922a071c58ab0108c"}, - {file = "regex-2020.9.27-cp39-cp39-manylinux1_i686.whl", hash = "sha256:84cada8effefe9a9f53f9b0d2ba9b7b6f5edf8d2155f9fdbe34616e06ececf81"}, - {file = "regex-2020.9.27-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:816064fc915796ea1f26966163f6845de5af78923dfcecf6551e095f00983650"}, - {file = "regex-2020.9.27-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:5d892a4f1c999834eaa3c32bc9e8b976c5825116cde553928c4c8e7e48ebda67"}, - {file = "regex-2020.9.27-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:c9443124c67b1515e4fe0bb0aa18df640965e1030f468a2a5dc2589b26d130ad"}, - {file = "regex-2020.9.27-cp39-cp39-win32.whl", hash = "sha256:49f23ebd5ac073765ecbcf046edc10d63dcab2f4ae2bce160982cb30df0c0302"}, - {file = "regex-2020.9.27-cp39-cp39-win_amd64.whl", hash = "sha256:3d20024a70b97b4f9546696cbf2fd30bae5f42229fbddf8661261b1eaff0deb7"}, {file = "regex-2020.9.27.tar.gz", hash = "sha256:a6f32aea4260dfe0e55dc9733ea162ea38f0ea86aa7d0f77b15beac5bf7b369d"}, ] requests = [ @@ -1060,9 +1028,6 @@ sniffio = [ {file = "sniffio-1.1.0-py3-none-any.whl", hash = "sha256:20ed6d5b46f8ae136d00b9dcb807615d83ed82ceea6b2058cecb696765246da5"}, {file = "sniffio-1.1.0.tar.gz", hash = "sha256:8e3810100f69fe0edd463d02ad407112542a11ffdc29f67db2bf3771afb87a21"}, ] -stringcase = [ - {file = "stringcase-1.2.0.tar.gz", hash = "sha256:48a06980661908efe8d9d34eab2b6c13aefa2163b3ced26972902e3bdfd87008"}, -] taskipy = [ {file = "taskipy-1.7.0-py3-none-any.whl", hash = "sha256:9e284c10898e9dee01a3e72220b94b192b1daa0f560271503a6df1da53d03844"}, {file = "taskipy-1.7.0.tar.gz", hash = "sha256:960e480b1004971e76454ecd1a0484e640744a30073a1069894a311467f85ed8"}, @@ -1079,28 +1044,19 @@ typed-ast = [ {file = "typed_ast-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75"}, {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652"}, {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"}, - {file = "typed_ast-1.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:fcf135e17cc74dbfbc05894ebca928ffeb23d9790b3167a674921db19082401f"}, {file = "typed_ast-1.4.1-cp36-cp36m-win32.whl", hash = "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1"}, {file = "typed_ast-1.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa"}, {file = "typed_ast-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614"}, {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41"}, {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b"}, - {file = "typed_ast-1.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:f208eb7aff048f6bea9586e61af041ddf7f9ade7caed625742af423f6bae3298"}, {file = "typed_ast-1.4.1-cp37-cp37m-win32.whl", hash = "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe"}, {file = "typed_ast-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355"}, {file = "typed_ast-1.4.1-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6"}, {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907"}, {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d"}, - {file = "typed_ast-1.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:7e4c9d7658aaa1fc80018593abdf8598bf91325af6af5cce4ce7c73bc45ea53d"}, {file = "typed_ast-1.4.1-cp38-cp38-win32.whl", hash = "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c"}, {file = "typed_ast-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4"}, {file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"}, - {file = "typed_ast-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c"}, - {file = "typed_ast-1.4.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072"}, - {file = "typed_ast-1.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91"}, - {file = "typed_ast-1.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d"}, - {file = "typed_ast-1.4.1-cp39-cp39-win32.whl", hash = "sha256:b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395"}, - {file = "typed_ast-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c"}, {file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"}, ] typer = [ diff --git a/pyproject.toml b/pyproject.toml index a3f93c8c6..a75efd066 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ include = ["CHANGELOG.md", "openapi_python_client/py.typed"] [tool.poetry.dependencies] python = "^3.6" jinja2 = "^2.11.1" -stringcase = "^1.2.0" typer = "^0.3" colorama = {version = "^0.4.3", markers = "sys_platform == 'win32'"} shellingham = "^1.3.2" diff --git a/tests/test_parser/test_properties/test_schemas.py b/tests/test_parser/test_properties/test_schemas.py index 7d961f802..42dd6c323 100644 --- a/tests/test_parser/test_properties/test_schemas.py +++ b/tests/test_parser/test_properties/test_schemas.py @@ -14,19 +14,19 @@ def test_class_from_string_default_config(): @pytest.mark.parametrize( "class_override, module_override, expected_class, expected_module", ( - (None, None, "_MyResponse", "_my_response"), + (None, None, "MyResponse", "my_response"), ("MyClass", None, "MyClass", "my_class"), ("MyClass", "some_module", "MyClass", "some_module"), - (None, "some_module", "_MyResponse", "some_module"), + (None, "some_module", "MyResponse", "some_module"), ), ) def test_class_from_string(class_override, module_override, expected_class, expected_module): from openapi_python_client.config import ClassOverride, Config from openapi_python_client.parser.properties import Class - ref = "#/components/schemas/_MyResponse" + ref = "#/components/schemas/MyResponse" config = Config( - class_overrides={"_MyResponse": ClassOverride(class_name=class_override, module_name=module_override)} + class_overrides={"MyResponse": ClassOverride(class_name=class_override, module_name=module_override)} ) result = Class.from_string(string=ref, config=config) diff --git a/tests/test_utils.py b/tests/test_utils.py index 64ed495d8..4276f0268 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,6 +12,12 @@ def test_snake_case_from_pascal_with_acronyms(): assert utils.snake_case("HTTPResponse") == "http_response" assert utils.snake_case("APIClientHTTPResponse") == "api_client_http_response" assert utils.snake_case("OAuthClientHTTPResponse") == "o_auth_client_http_response" + assert utils.snake_case("S3Config") == "s3_config" + + +def test_snake_case_from_pascal_with_numbers(): + assert utils.snake_case("Response200") == "response_200" + assert utils.snake_case("Response200WithContent") == "response_200_with_content" def test_snake_case_from_pascal(): @@ -20,6 +26,7 @@ def test_snake_case_from_pascal(): def test_snake_case_from_camel(): assert utils.snake_case("httpResponseLowerCamel") == "http_response_lower_camel" + assert utils.snake_case("connectionID") == "connection_id" def test_kebab_case(): @@ -59,6 +66,8 @@ def test_to_valid_python_identifier(): ("snake_case", "SnakeCase"), ("TLAClass", "TLAClass"), ("Title Case", "TitleCase"), + ("s3_config", "S3Config"), + ("__LeadingUnderscore", "LeadingUnderscore"), ], ) def test_pascalcase(before, after):