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 e6e8275f8..85e5243ec 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 @@ -23,6 +23,7 @@ from .import_ import Import from .model_from_all_of import ModelFromAllOf from .model_name import ModelName +from .model_reference_with_periods import ModelReferenceWithPeriods from .model_with_additional_properties_inlined import ModelWithAdditionalPropertiesInlined from .model_with_additional_properties_inlined_additional_property import ( ModelWithAdditionalPropertiesInlinedAdditionalProperty, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py new file mode 100644 index 000000000..15bab8de5 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py @@ -0,0 +1,44 @@ +from typing import Any, Dict, List, Type, TypeVar + +import attr + +T = TypeVar("T", bound="ModelReferenceWithPeriods") + + +@attr.s(auto_attribs=True) +class ModelReferenceWithPeriods: + """A Model with periods in its reference""" + + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + model_reference_with_periods = cls() + + model_reference_with_periods.additional_properties = d + return model_reference_with_periods + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 4131446a9..22e095511 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -1902,6 +1902,10 @@ }, "None": { "type": "object" + }, + "model.reference.with.Periods": { + "type": "object", + "description": "A Model with periods in its reference" } } } diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py index 223739011..cb1ac611c 100644 --- a/openapi_python_client/utils.py +++ b/openapi_python_client/utils.py @@ -3,7 +3,7 @@ from keyword import iskeyword from typing import Any, List -DELIMITERS = " _-" +DELIMITERS = r"\. _-" class PythonIdentifier(str): diff --git a/tests/test_utils.py b/tests/test_utils.py index 2345aaee8..97f0bee2a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -47,6 +47,7 @@ def test_empty_is_prefixed(self): ("Response200Okay", ["Response", "200", "Okay"]), ("S3Config", ["S3", "Config"]), ("s3config", ["s3config"]), + ("fully.qualified.Name", ["fully", "qualified", "Name"]), ], ) def test_split_words(before, after): @@ -83,8 +84,8 @@ def test_kebab_case(): assert utils.kebab_case("keep_alive") == "keep-alive" -def test__sanitize(): - assert utils.sanitize("something*~with lots_- of weird things}=") == "somethingwith lots_- of weird things" +def test_sanitize(): + assert utils.sanitize("some.thing*~with lots_- of weird things}=") == "some.thingwith lots_- of weird things" def test_no_string_escapes():