Skip to content

Commit

Permalink
mssgen: preserve existing camel cases
Browse files Browse the repository at this point in the history
an edge case like MultifundchannelChannel_idsChannel_type
was previously converted to MultifundchannelChannelIdschannelType
instead of the correct MultifundchannelChannelIdsChannelType
  • Loading branch information
daywalker90 authored and cdecker committed Apr 17, 2024
1 parent c4edec8 commit 4d306e2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contrib/msggen/msggen/gen/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,15 @@ def generate_composite(self, prefix, field: CompositeField):
def to_camel_case(self, snake_str):
components = snake_str.split('_')
# We capitalize the first letter of each component except the first one
# with the 'title' method and join them together.
return components[0] + ''.join(x.title() for x in components[1:])
# with the 'capitalize' method and join them together, while preserving
# existing camel cases.
camel_case = components[0]
for word in components[1:]:
if not word.isupper():
camel_case += word[0].upper() + word[1:]
else:
camel_case += word.capitalize()
return camel_case

def generate_requests(self, service):
for meth in service.methods:
Expand Down

0 comments on commit 4d306e2

Please sign in to comment.