Skip to content

Fix PascalCase transformation from Title Case. Fixes #271 #274

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
Dec 21, 2020
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
3 changes: 1 addition & 2 deletions openapi_python_client/parser/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class Reference:
def from_ref(ref: str) -> "Reference":
""" Get a Reference from the openapi #/schemas/blahblah string """
ref_value = ref.split("/")[-1]
# ugly hack to avoid stringcase ugly pascalcase output when ref_value isn't snake case
class_name = utils.pascal_case(ref_value.replace(" ", ""))
class_name = utils.pascal_case(ref_value)

if class_name in class_overrides:
return class_overrides[class_name]
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 @@ -26,7 +26,7 @@ def snake_case(value: str) -> str:


def pascal_case(value: str) -> str:
return fix_keywords(stringcase.pascalcase(sanitize(value)))
return fix_keywords(stringcase.pascalcase(sanitize(value.replace(" ", ""))))


def kebab_case(value: str) -> str:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from openapi_python_client import utils


Expand Down Expand Up @@ -41,3 +43,16 @@ def test_to_valid_python_identifier():
assert utils.to_valid_python_identifier("1") == "field_1"
assert utils.to_valid_python_identifier("$") == "field_"
assert utils.to_valid_python_identifier("for") == "for_"


@pytest.mark.parametrize(
"before, after",
[
("PascalCase", "PascalCase"),
("snake_case", "SnakeCase"),
("TLAClass", "TLAClass"),
("Title Case", "TitleCase"),
],
)
def test_pascalcase(before, after):
assert utils.pascal_case(before) == after