-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat: respect gogoproto nullable #2
Conversation
@@ -312,6 +362,96 @@ pub fn serde_alias_id_with_uppercased(s: ItemStruct) -> ItemStruct { | |||
syn::ItemStruct { fields, ..s } | |||
} | |||
|
|||
fn is_field_gogoproto_nullable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move it after pub funcs
false | ||
} | ||
|
||
pub fn respect_gogoproto_nullable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can have tests for it. would be nice to get to know if some of this fragile logic breaks because of either ours or counterparty's changes to proto tags or GOGOPROTO_NULLABLE_EXTENSION_FIELD_NUMBER
or something else. for example, apply serialization/deserialization on several proto messages taken from different sources and make sure the results re optionality are as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply serialization/deserialization on several proto messages taken from different sources and make sure the results re optionality are as expected
I don't get it, could you elaborate? What exactly do you want to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have some tests that would cover proto-to-rust code generation in terms of gogoproto_nullable with verification of the end rust struct fields optionality. ideally end-to-end tests with different (from different sources e.g. neutron, cosmos-sdk, osmosis, etc.) proto messages as input and rust structure fields assertion (gogoproto_nullable fields are optional, other are required). that could be done as a separate task. what do you think?
@@ -151,12 +154,14 @@ fn transform_items( | |||
let s = transformers::add_derive_eq_struct(&s); | |||
let s = transformers::append_attrs_struct(src, &s, descriptor); | |||
let s = transformers::serde_alias_id_with_uppercased(s); | |||
let s = transformers::respect_gogoproto_nullable(s, descriptor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since structures are always optional as a result of rust proto generation (e.g. this field is not supposed to be optional), I wonder if it's possible to do the opposite: make structs optional only if there is a gogoproto_nullable set, and make them required otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure it's possible, but it's out of scope. Could you create a task for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will do
Currently rust protobuf libraries do not respect
gogoproto.nullable
option in proto files, thus some fields are required i generated rust code, but go has a different behaviour.This PR solves this problem in a kinda dirty way, but it does solve it
Related PRs: