Camelcase is lost (Javascript protoc) · Issue #17 · protocolbuffers/protobuf-javascript · GitHub
Skip to content

Camelcase is lost (Javascript protoc) #17

Open

Description

@zim32

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

Activity

  1. k10-patil commented on Jun 17, 2021

    @k10-patil

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

  2. petermetz commented on Aug 11, 2021

    @petermetz

    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";
  3. trent1000 commented on Aug 11, 2021

    @trent1000
  4. youurayy commented on Aug 28, 2021

    @youurayy

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

  5. thesayyn commented on Dec 8, 2021

    @thesayyn

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

    also seen on #37

  6. dibenede commented on Sep 2, 2022

    @dibenede
    Contributor

    This is fixable and is inconsistent with other proto runtimes. However, it poses a compatibility problem. The issue is here:

    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.

  7. sarahec commented on Oct 23, 2022

    @sarahec

    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.

  8. jmzwcn commented on Oct 25, 2023

    @jmzwcn
    syntax = "proto3";
    
    message Test {
      string some_field_with_camel_case = 1;
    }

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions