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

Support camelCase fields (via a json_names option). #142

Merged
merged 5 commits into from
Jun 4, 2022

Conversation

zacharyvoase
Copy link

I know this has been asked for a lot, so I decided to implement it. It turns out FieldDescriptorProto already has a json_name for each field, as generated by the protobuf compiler, so this option just causes the compiler to use that (instead of fieldDescriptor.name) for all generated descriptors. Obviously I left in the default behavior of using the names from the proto definitions as-is, for backwards compatibility.

Let me know if I need to add more tests; I wrote a simple smoke test that seems to work though.

@zacharyvoase
Copy link
Author

I should mention, this has the benefit that if the proto author overrides the JSON name manually, that will be used. e.g.:

message Msg {
  string a_field = 1 [json_name = "customFieldName"];
}

then the generated JS will use message.customFieldName.

@thesayyn
Copy link
Owner

thesayyn commented Jun 1, 2022

Hey. thanks for working on this. I will look into it sometime this week.

Copy link
Owner

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks

@thesayyn thesayyn merged commit 1022c90 into thesayyn:main Jun 4, 2022
@thesayyn thesayyn mentioned this pull request Jul 9, 2022
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

Successfully merging this pull request may close these issues.

2 participants