Keep '_' in attribute name in generated code
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@@
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.
Ok, nice. What option is this exactly and how to use it?
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
https://github.com/FirebaseExtended/protobuf-rules-gen/blob/d413219bca50d96b58247d2c5b4981d9182b28b2/firebase_rules_generator/generator.cc#L98
@rockwotj thanks for chiming in here!