Skip to content

Commit 999a81d

Browse files
committed
Enhance split words
Keep "Response200" as "response_200", but don't make "s3config" become "s_3_config". :)
1 parent a731477 commit 999a81d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Diff for: openapi_python_client/parser/properties/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def build_union_property(
354354
sub_properties: List[Property] = []
355355
for i, sub_prop_data in enumerate(chain(data.anyOf, data.oneOf)):
356356
sub_prop, schemas = property_from_data(
357-
name=f"{name}_type{i}",
357+
name=f"{name}_type_{i}",
358358
required=required,
359359
data=sub_prop_data,
360360
schemas=schemas,

Diff for: openapi_python_client/utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ def sanitize(value: str) -> str:
1212

1313

1414
def split_words(value: str) -> List[str]:
15-
"""Split a string on non-capital letters and known delimiters"""
16-
value = " ".join(re.split("([A-Z]?[a-z]+)", value))
15+
"""Split a string on words and known delimiters"""
16+
# We can't guess words if there is no capital letter
17+
if any(c.isupper() for c in value):
18+
value = " ".join(re.split("([A-Z]?[a-z]+)", value))
1719
return re.findall(rf"[^{delimiters}]+", value)
1820

1921

Diff for: tests/test_utils.py

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
from openapi_python_client import utils
44

55

6+
@pytest.mark.parametrize(
7+
"before, after",
8+
[
9+
("connectionID", ["connection", "ID"]),
10+
("connection_id", ["connection", "id"]),
11+
("connection-id", ["connection", "id"]),
12+
("Response200", ["Response", "200"]),
13+
("Response200Okay", ["Response", "200", "Okay"]),
14+
("S3Config", ["S3", "Config"]),
15+
("s3config", ["s3config"]),
16+
],
17+
)
18+
def test_split_words(before, after):
19+
assert utils.split_words(before) == after
20+
21+
622
def test_snake_case_uppercase_str():
723
assert utils.snake_case("HTTP") == "http"
824
assert utils.snake_case("HTTP RESPONSE") == "http_response"

0 commit comments

Comments
 (0)