grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.64k stars 765 forks source link

is it possible to keep message field name unchange while generate _pb.js files ? #1133

Closed ai2soft closed 3 years ago

ai2soft commented 3 years ago

Hi guys , i defineded some messages


message AppResult {
    bool IsSucceed = 1;
    string Error = 2;
    oneof Data {
        LoginResult LoginResult = 3;
    };
}

message LoginResult{
    string Token = 1;
    google.protobuf.Timestamp SessionExpired = 2;   
}

as you can see, the message's fields are well formatted. but , when i generated the files of XXXX_pb.js by command

--grpc-web_out=import_style=commonjs,mode=grpcwebtext:.

the target names were changed to get{[A-Z]}{[a-z]+} like. likes:

getError() 
getLoginresult()
getToken()
getSessionexpired()

why it should be like that ? can it be kept unchanged? likes :

getError() 
getLoginResult()
getToken()
getSessionExpired()
renkei commented 3 years ago

In the proto file, set the field name of a message to e.g. session_expired instead of SessionExpired then the generated code contains getSessionExpired() and setSessionExpired(). I assume that this is a relict from the early days of protobuf for JS to keep backward compatibility.

It's indeed annoying, especially if you use the proto file for other languages like C# as well because there the field name SessionExpired results (as expected) in a property SessionExpired.

ai2soft commented 3 years ago

hi, thanks for reply. i build a C# project to rewrite the field names . as you mentioned, i use C# at the same time.


发件人: renkei @.> 发送时间: 2021年9月23日 4:58 收件人: grpc/grpc-web @.> 抄送: jin li Zhang @.>; Author @.> 主题: Re: [grpc/grpc-web] is it possible to keep message field name unchange while generate _pb.js files ? (#1133)

In the proto file, set the field name of a message to e.g. session_expired instead of SessionExpired then the generated code contains getSessionExpired() and setSessionExpired. I assume that this is a relict from the early days of protobuf for JS to keep backward compatibility.

It's indeed annoying, especially if you use the proto file for other languages like C# as well because there the field name SessionExpired results (as expected) in a property SessionResult.

― You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/grpc/grpc-web/issues/1133#issuecomment-925324558, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUBCPWINQEXHE5ZTNQBWY63UDI7NZANCNFSM5DO4YLVQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.