Camelcase is lost (Javascript protoc)
What version of protobuf and what language are you using? 3.16.0 (Linux x86_64) Javascript
Operation system Ubuntu 18.04
What runtime / compiler are you using (e.g., python version or gcc version)
What did you do? Create proto file (syntax 3)
syntax = "proto3";
message Test {
string someFieldWithCamelCase = 1;
}
run
protoc --js_out=import_style=commonjs,binary:out test.proto
Got
proto.Test.prototype.setSomefieldwithcamelcase = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};
What did you expect to see
proto.Test.prototype.setSomeFieldWithCamelCase = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};
What did you see instead? Camelcase is lost
any updates on this? facing same issue. It would be nightmare to edit fieldnames when dealing with large number of proto messages!
Having the same problem, just came here to gently bump the thread. :-)
Additional testing also revealed that if I load the proto files directly with grpc-loader[1], then the dynamically generated JS code has the correct (camel) casing.
[1]:
import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
What are talking about my phone
On Thu, Jun 17, 2021, 3:01 AM k10-patil @.***> wrote:
any updates on this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <protocolbuffers/protobuf-javascript#17>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWBKWOOJEUTRFUNNHRCMR3TTGMTTANCNFSM44Y7DD6Q .
This is an absolute deal-breaker of using google-protobuf in javascript.
I don’t think that google will change this behaviour anytime soon.
also seen on protocolbuffers/protobuf-javascript#37
This is fixable and is inconsistent with other proto runtimes. However, it poses a compatibility problem. The issue is here: https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/generator/js_generator.cc#L290
The immediate workaround is to use underscore_naming style rather than camelCase.
The fix would be to flag gate the naming behavior. We'll need to consider which direction the flagging should operate.
My suggestion: the default behavior should match the style guide (which calls for snake_case in field names, and CamelCase for the proto name), and have a flag to enable the extension (or extensions).
If the flag's not set, this could emit a warning on seeing a CamelCase field name.
P.S. I'm willing to take on this patch once we have agreement on how it should work.
syntax = "proto3";
message Test {
string some_field_with_camel_case = 1;
}
https://protobuf.dev/programming-guides/style/#message-field-names