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

Serde renaming for snake-cased properties in rust plugins types #1700

Merged
merged 4 commits into from
Apr 19, 2023

Conversation

namesty
Copy link
Collaborator

@namesty namesty commented Apr 18, 2023

When serializing arguments in subinvocations, plugins by default send types with snake-cased properties as that's Rust convention, and our codegen respects it. However, our ABI type definitions may not be all snake-cased, some might be, others might be camel-cased or a mix, etc. This leads to data translation errors when using types that contain properties like that, as the freely-cased schema props don't match the snake-cased rust struct ones.

Additionally when use the msgpack! macro in Rust we should pass arguments that match the ABI definitions.

Therefore, this PRs leverages serde_rename to solve both of these issues. When serializing from a struct to a different format, it will convert any snake-cased prop to the case used in the ABI; and when deserializing from data that's freely-cased, it will handle the conversion to snake-cased appropriately.

The implementation logic is:

  1. Check if original property name contains any uppercase letter
  2. If it does, add the rename annotation, since the codegen will convert it to lower-snake-case through the toLower helper function
  3. Rename will be the original property name from the ABI.

I updated the binding examples to include some mixed cases examples

@dOrgJelli dOrgJelli merged commit f129625 into origin-dev Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants