Skip to content

Commit

Permalink
msggen: fix edge cases in rust composite field names
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 authored and cdecker committed May 16, 2024
1 parent 2a63b1a commit 03b75f7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contrib/msggen/msggen/gen/rpc/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def gen_primitive(p):


def rename_if_necessary(original, name):
if original != name:
return f' #[serde(rename = "{original}")]\n'
if str(original) != str(name):
return f" #[serde(rename = \"{original}\")]\n"
else:
return f""

Expand Down Expand Up @@ -268,10 +268,11 @@ def gen_composite(c, meta) -> Tuple[str, str]:
defi = ""
if c.deprecated:
defi += " #[deprecated]\n"
defi += rename_if_necessary(c.name, c.normalized())
if not c.optional:
defi += f" pub {c.name}: {c.typename},\n"
defi += f" pub {c.normalized()}: {c.typename},\n"
else:
defi += f' #[serde(skip_serializing_if = "Option::is_none")]\n pub {c.name}: Option<{c.typename}>,\n'
defi += f" #[serde(skip_serializing_if = \"Option::is_none\")]\n pub {c.normalized()}: Option<{c.typename}>,\n"

return defi, r

Expand Down

0 comments on commit 03b75f7

Please sign in to comment.