Skip to content
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

Fix ap_is -> apis #2536

Merged
merged 2 commits into from
Jun 20, 2024
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
4 changes: 2 additions & 2 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import dateutil.parser

from .utils import snake_case, camel_case, untitle_case, schema_name
from .utils import safe_snake_case, snake_case, camel_case, untitle_case, schema_name

PRIMITIVE_TYPES = ["string", "number", "boolean", "integer"]

Expand Down Expand Up @@ -81,7 +81,7 @@ def block_comment(comment, prefix="#", first_line=True):


def model_filename(name):
filename = snake_case(name)
filename = safe_snake_case(name)
last = filename.split("_")[-1]
if last in SUFFIXES:
filename += "_"
Expand Down
8 changes: 8 additions & 0 deletions .generator/src/generator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
PATTERN_LEADING_ALPHA = re.compile(r"(.)([A-Z][a-z]+)")
PATTERN_FOLLOWING_ALPHA = re.compile(r"([a-z0-9])([A-Z])")
PATTERN_WHITESPACE = re.compile(r"\W")
# Other client generators have more edge cases defined but adding them here could cause backwards-incompatible breaking changes.
EDGE_CASES = {"APIs": "Apis"}


def snake_case(value):
Expand All @@ -16,6 +18,12 @@ def snake_case(value):
return PATTERN_DOUBLE_UNDERSCORE.sub("_", s1)


def safe_snake_case(value):
for token, replacement in EDGE_CASES.items():
value = value.replace(token, replacement)
return snake_case(value)


def upperfirst(value):
return value[0].upper() + value[1:]

Expand Down
Loading