feat: honor json_name option#1825
Conversation
…iled for multiple languages, to conform to whatever random casing rules were chosen for the project: - The .proto convention is to use lower_snake_case for field names, and UPPER_SNAKE_CASE for enum names - C++ (via protoc) simply uses lower_snake_case for field names - C# (via protobuf-net) uses PascalCase for both field and enum names, and has options for customizing the names: https://github.com/protobuf-net/protobuf-net/blob/main/src/Tools/protogen.proto - JavaScript (via protobuf.js) uses camelCase for field names, and the json_name attribute can now be used to customize the name Example: message NetworkAdapter { string get_ip_address = 1 [json_name = "getIPAddress", (.protobuf_net.fieldopt).name ="GetIPAddress"]; } Default names without the options: - C++: get_ip_address (unchanged) - C#: GetIpAddress - JS: getIpAddress
|
Can we prioritize this review? We need it as well. |
|
Will this change also use json_name for files generated statically? |
|
Any update on this? Would really like to see this land. |
|
it seems we have a solution here for this |
|
The linked comment is not exactly a solution as it doesn't respect the explicitly defined json_name. |
|
Is there any way I could help this PR move forward and get merged? I just did a quick test against |
alexander-fenster
left a comment
There was a problem hiding this comment.
The code looks good to me, my main concern here is that it's technically a breaking change. The code that used the original field names will stop working if the proto defines json_name for those fields. I feel it's a little bit more serious than https://xkcd.com/1172/ so I would rather stay on the safe side and call it a major version.
What do you folks think if we mark it as a breaking feature, and combine it with dropping Node.js v12 support to release it as 8.0.0? I'll wait for a few days here for any feedback from the community.
|
+1 to releasing it as a major version. This change will definitely break my current use case. Can this be behind a build flag/option? |
|
Alternatively this could be a runtime option which is off by default. |
|
Runtime option might not work with folks like us using the statically generated files. |
|
I think it can technically go to |
|
I am happy to see that this is getting traction, but sorry, I no longer have time to contribute to this. |
Honor the json_name option. This is useful when a .proto file is compiled for multiple languages, to conform to whatever random casing rules were chosen for the project:
Example:
Default names without the options:
Fixes #992, fixes #1245, fixes #1775