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

Have an option to use snake_case for message properties #564

Closed
vgoloviznin opened this issue Dec 16, 2016 · 12 comments
Closed

Have an option to use snake_case for message properties #564

vgoloviznin opened this issue Dec 16, 2016 · 12 comments

Comments

@vgoloviznin
Copy link

protobuf.js version: 6.1.1

I'm running pbjs utility to generate JSON for my proto files, but the issue is that it generates camelCase property names (proto files have snake_case).

Is there already some configuration for this (found a broken link to wiki article) or is it possible to include one?

@dcodeIO
Copy link
Member

dcodeIO commented Dec 16, 2016

Currently, v6 always converts to camel case for simplicity. Google's JS implementation also does this. pbjs's proto2/3 targets always convert back.

Do you have a specific use case where this fails or snake_case is absolutely required?

@vgoloviznin
Copy link
Author

Can't say that I have a hard requirement for snake_case :)
We have all documentation for communication between services where all field names are in snake case, so it's just easier to blindly follow the documentation (or reading the proto file) without thinking about camel case conversion

@dcodeIO
Copy link
Member

dcodeIO commented Dec 16, 2016

pbjs now supports the option --keep-case that skips the camel case conversion. I haven't tested this for edge cases in detail, yet, so let me know if there are any issues.

@vgoloviznin
Copy link
Author

@dcodeIO cool! When will it get released on npm?

@dcodeIO
Copy link
Member

dcodeIO commented Dec 16, 2016

Maybe tonight as 6.2.1 if there are no more pending issues.

@vgoloviznin
Copy link
Author

Awesome, thanks for the quick fix!

I will check during the weekend for our definition

@dcodeIO
Copy link
Member

dcodeIO commented Dec 16, 2016

It's on npm now! Feel free to reopen if there are issues.

@dcodeIO dcodeIO closed this as completed Dec 16, 2016
@thirstyfish
Copy link

Hi!
Apologies if it's a silly question, I'm just familiarising myself with your library, but haven't found an answer to this in the docs, this issue is as close as I got.
I have the same problem as the OP, but I'm not using the CLI to generate a json file.
Is there an equivalent option that can be set in the proto file or elsewhere that will have the same effect (leave the snake case intact) in case I'd like to load the raw proto file directly with protobuf.load()?
Thanks!

@dcodeIO
Copy link
Member

dcodeIO commented Feb 19, 2017

Yes: Root#load

var root = new protobuf.Root();
root.load(..., { keepCase: true }).then(...);

@thirstyfish
Copy link

Great, thanks for your help!

@samkeke
Copy link

samkeke commented Jan 23, 2018

Thank you help,

I finally found the answer

@breakpointninja
Copy link

Is there a way to --keep-case for static modules. Its a big problem when using typescript.

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

No branches or pull requests

5 participants