protobuf-javascript icon indicating copy to clipboard operation
protobuf-javascript copied to clipboard

Camelcase is lost (Javascript protoc)

Open zim32 opened this issue 4 years ago • 8 comments

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

zim32 avatar May 12 '21 16:05 zim32

any updates on this? facing same issue. It would be nightmare to edit fieldnames when dealing with large number of proto messages!

k10-patil avatar Jun 17 '21 07:06 k10-patil

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";

petermetz avatar Aug 11 '21 04:08 petermetz

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 .

trent1000 avatar Aug 11 '21 04:08 trent1000

This is an absolute deal-breaker of using google-protobuf in javascript.

youurayy avatar Aug 28 '21 12:08 youurayy

I don’t think that google will change this behaviour anytime soon.

also seen on protocolbuffers/protobuf-javascript#37

thesayyn avatar Dec 08 '21 14:12 thesayyn

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.

dibenede avatar Sep 02 '22 22:09 dibenede

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.

sarahec avatar Oct 23 '22 18:10 sarahec

syntax = "proto3";

message Test {
  string some_field_with_camel_case = 1;
}

https://protobuf.dev/programming-guides/style/#message-field-names

jmzwcn avatar Oct 25 '23 03:10 jmzwcn