Skip to content

Enhance split words #413

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 2 commits into from
May 24, 2021
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 @@ -19,8 +19,8 @@ class AModelWithPropertiesReferenceThatAreNotObject:
str_properties_ref: List[str]
date_properties_ref: List[datetime.date]
datetime_properties_ref: List[datetime.datetime]
int_32_properties_ref: List[int]
int_64_properties_ref: List[int]
int32_properties_ref: List[int]
int64_properties_ref: List[int]
float_properties_ref: List[float]
double_properties_ref: List[float]
file_properties_ref: List[File]
Expand All @@ -29,8 +29,8 @@ class AModelWithPropertiesReferenceThatAreNotObject:
str_properties: List[str]
date_properties: List[datetime.date]
datetime_properties: List[datetime.datetime]
int_32_properties: List[int]
int_64_properties: List[int]
int32_properties: List[int]
int64_properties: List[int]
float_properties: List[float]
double_properties: List[float]
file_properties: List[File]
Expand All @@ -39,8 +39,8 @@ class AModelWithPropertiesReferenceThatAreNotObject:
str_property_ref: str
date_property_ref: datetime.date
datetime_property_ref: datetime.datetime
int_32_property_ref: int
int_64_property_ref: int
int32_property_ref: int
int64_property_ref: int
float_property_ref: float
double_property_ref: float
file_property_ref: File
Expand Down Expand Up @@ -71,9 +71,9 @@ def to_dict(self) -> Dict[str, Any]:

datetime_properties_ref.append(componentsschemas_an_other_array_of_date_time_item)

int_32_properties_ref = self.int_32_properties_ref
int32_properties_ref = self.int32_properties_ref

int_64_properties_ref = self.int_64_properties_ref
int64_properties_ref = self.int64_properties_ref

float_properties_ref = self.float_properties_ref

Expand Down Expand Up @@ -108,9 +108,9 @@ def to_dict(self) -> Dict[str, Any]:

datetime_properties.append(componentsschemas_an_array_of_date_time_item)

int_32_properties = self.int_32_properties
int32_properties = self.int32_properties

int_64_properties = self.int_64_properties
int64_properties = self.int64_properties

float_properties = self.float_properties

Expand All @@ -130,8 +130,8 @@ def to_dict(self) -> Dict[str, Any]:
date_property_ref = self.date_property_ref.isoformat()
datetime_property_ref = self.datetime_property_ref.isoformat()

int_32_property_ref = self.int_32_property_ref
int_64_property_ref = self.int_64_property_ref
int32_property_ref = self.int32_property_ref
int64_property_ref = self.int64_property_ref
float_property_ref = self.float_property_ref
double_property_ref = self.double_property_ref
file_property_ref = self.file_property_ref.to_tuple()
Expand All @@ -146,8 +146,8 @@ def to_dict(self) -> Dict[str, Any]:
"str_properties_ref": str_properties_ref,
"date_properties_ref": date_properties_ref,
"datetime_properties_ref": datetime_properties_ref,
"int32_properties_ref": int_32_properties_ref,
"int64_properties_ref": int_64_properties_ref,
"int32_properties_ref": int32_properties_ref,
"int64_properties_ref": int64_properties_ref,
"float_properties_ref": float_properties_ref,
"double_properties_ref": double_properties_ref,
"file_properties_ref": file_properties_ref,
Expand All @@ -156,8 +156,8 @@ def to_dict(self) -> Dict[str, Any]:
"str_properties": str_properties,
"date_properties": date_properties,
"datetime_properties": datetime_properties,
"int32_properties": int_32_properties,
"int64_properties": int_64_properties,
"int32_properties": int32_properties,
"int64_properties": int64_properties,
"float_properties": float_properties,
"double_properties": double_properties,
"file_properties": file_properties,
Expand All @@ -166,8 +166,8 @@ def to_dict(self) -> Dict[str, Any]:
"str_property_ref": str_property_ref,
"date_property_ref": date_property_ref,
"datetime_property_ref": datetime_property_ref,
"int32_property_ref": int_32_property_ref,
"int64_property_ref": int_64_property_ref,
"int32_property_ref": int32_property_ref,
"int64_property_ref": int64_property_ref,
"float_property_ref": float_property_ref,
"double_property_ref": double_property_ref,
"file_property_ref": file_property_ref,
Expand Down Expand Up @@ -207,9 +207,9 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

datetime_properties_ref.append(componentsschemas_an_other_array_of_date_time_item)

int_32_properties_ref = cast(List[int], d.pop("int32_properties_ref"))
int32_properties_ref = cast(List[int], d.pop("int32_properties_ref"))

int_64_properties_ref = cast(List[int], d.pop("int64_properties_ref"))
int64_properties_ref = cast(List[int], d.pop("int64_properties_ref"))

float_properties_ref = cast(List[float], d.pop("float_properties_ref"))

Expand Down Expand Up @@ -249,9 +249,9 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

datetime_properties.append(componentsschemas_an_array_of_date_time_item)

int_32_properties = cast(List[int], d.pop("int32_properties"))
int32_properties = cast(List[int], d.pop("int32_properties"))

int_64_properties = cast(List[int], d.pop("int64_properties"))
int64_properties = cast(List[int], d.pop("int64_properties"))

float_properties = cast(List[float], d.pop("float_properties"))

Expand All @@ -276,9 +276,9 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

datetime_property_ref = isoparse(d.pop("datetime_property_ref"))

int_32_property_ref = d.pop("int32_property_ref")
int32_property_ref = d.pop("int32_property_ref")

int_64_property_ref = d.pop("int64_property_ref")
int64_property_ref = d.pop("int64_property_ref")

float_property_ref = d.pop("float_property_ref")

Expand All @@ -293,8 +293,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
str_properties_ref=str_properties_ref,
date_properties_ref=date_properties_ref,
datetime_properties_ref=datetime_properties_ref,
int_32_properties_ref=int_32_properties_ref,
int_64_properties_ref=int_64_properties_ref,
int32_properties_ref=int32_properties_ref,
int64_properties_ref=int64_properties_ref,
float_properties_ref=float_properties_ref,
double_properties_ref=double_properties_ref,
file_properties_ref=file_properties_ref,
Expand All @@ -303,8 +303,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
str_properties=str_properties,
date_properties=date_properties,
datetime_properties=datetime_properties,
int_32_properties=int_32_properties,
int_64_properties=int_64_properties,
int32_properties=int32_properties,
int64_properties=int64_properties,
float_properties=float_properties,
double_properties=double_properties,
file_properties=file_properties,
Expand All @@ -313,8 +313,8 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
str_property_ref=str_property_ref,
date_property_ref=date_property_ref,
datetime_property_ref=datetime_property_ref,
int_32_property_ref=int_32_property_ref,
int_64_property_ref=int_64_property_ref,
int32_property_ref=int32_property_ref,
int64_property_ref=int64_property_ref,
float_property_ref=float_property_ref,
double_property_ref=double_property_ref,
file_property_ref=file_property_ref,
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def build_union_property(
sub_properties: List[Property] = []
for i, sub_prop_data in enumerate(chain(data.anyOf, data.oneOf)):
sub_prop, schemas = property_from_data(
name=f"{name}_type{i}",
name=f"{name}_type_{i}",
required=required,
data=sub_prop_data,
schemas=schemas,
Expand Down
6 changes: 4 additions & 2 deletions openapi_python_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def sanitize(value: str) -> str:


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))
"""Split a string on words and known delimiters"""
# We can't guess words if there is no capital letter
if any(c.isupper() for c in value):
value = " ".join(re.split("([A-Z]?[a-z]+)", value))
return re.findall(rf"[^{delimiters}]+", value)


Expand Down
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
from openapi_python_client import utils


@pytest.mark.parametrize(
"before, after",
[
("connectionID", ["connection", "ID"]),
("connection_id", ["connection", "id"]),
("connection-id", ["connection", "id"]),
("Response200", ["Response", "200"]),
("Response200Okay", ["Response", "200", "Okay"]),
("S3Config", ["S3", "Config"]),
("s3config", ["s3config"]),
],
)
def test_split_words(before, after):
assert utils.split_words(before) == after


def test_snake_case_uppercase_str():
assert utils.snake_case("HTTP") == "http"
assert utils.snake_case("HTTP RESPONSE") == "http_response"
Expand Down