Skip to content

fix: include period as known delimiter #546

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 4 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,10 @@
},
"None": {
"type": "object"
},
"model.reference.with.Periods": {
"type": "object",
"description": "A Model with periods in its reference"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from keyword import iskeyword
from typing import Any, List

DELIMITERS = " _-"
DELIMITERS = r"\. _-"


class PythonIdentifier(str):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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():
Expand Down