From 4d306e26919b04fb1c462aba18b5952a8b6cd74e Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:03:43 +0200 Subject: [PATCH] mssgen: preserve existing camel cases an edge case like MultifundchannelChannel_idsChannel_type was previously converted to MultifundchannelChannelIdschannelType instead of the correct MultifundchannelChannelIdsChannelType --- contrib/msggen/msggen/gen/grpc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/msggen/msggen/gen/grpc.py b/contrib/msggen/msggen/gen/grpc.py index 6f7857db35f7..8264d3f9dcdd 100644 --- a/contrib/msggen/msggen/gen/grpc.py +++ b/contrib/msggen/msggen/gen/grpc.py @@ -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: