Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep '_' in attribute name in generated code #40

Open
nilsreichardt opened this issue May 27, 2021 · 4 comments
Open

Keep '_' in attribute name in generated code #40

nilsreichardt opened this issue May 27, 2021 · 4 comments

Comments

@nilsreichardt
Copy link

Description

If you have an underscore (_) as an attribute name, then it will be transformed into camel case. I didn't except this.

Steps to reproduce

syntax = "proto3";

message Notification {
    map<string, string> fcm_token = 1;
    bool receive_notifications = 2;
}

will be generated into

// @@START_GENERATED_FUNCTIONS@@
function isNotificationMessage(resource) {
  return resource.keys().hasAll([]) &&
          (resource.keys().hasOnly(['receiveNotifications','fcmToken'])) &&
          ((!resource.keys().hasAny(['fcmToken'])) || (resource.fcmToken is map)) &&
          ((!resource.keys().hasAny(['receiveNotifications'])) || (resource.receiveNotifications is bool));
}
// @@END_GENERATED_FUNCTIONS@@

Is there a way to keep the _ in the attribute name? My excepted out is:

// @@START_GENERATED_FUNCTIONS@@
function isNotificationMessage(resource) {
  return resource.keys().hasAll([]) &&
          (resource.keys().hasOnly(['receive_notifications','fcm_token'])) &&
          ((!resource.keys().hasAny(['fcm_token'])) || (resource.fcm_token is map)) &&
          ((!resource.keys().hasAny(['receive_notifications'])) || (resource.receive_notifications is bool));
}
// @@END_GENERATED_FUNCTIONS@@
@rockwotj
Copy link
Contributor

There is a way to do this, right now we use the proto3 json mapping to get the names. You'd have to add an option to support keeping the original names around.

@nilsreichardt
Copy link
Author

Ok, nice. What option is this exactly and how to use it?

@rockwotj
Copy link
Contributor

Sorry I wasn't clear this is pretty straightforward to do, you have to change the code that looks at json_name and replace it with name in the places where it's used via a file option. There are existing examples of file options and here is one place we assume json naming

required.push_back(field->json_name());

@samtstern
Copy link
Contributor

@rockwotj thanks for chiming in here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants