Serde renaming for snake-cased properties in rust plugins types #1700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
toLower
helper functionI updated the binding examples to include some mixed cases examples