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

Comments

Projects
None yet
5 participants
@vgoloviznin

vgoloviznin commented Dec 16, 2016

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

This comment has been minimized.

Owner

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

This comment has been minimized.

vgoloviznin commented Dec 16, 2016

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 dcodeIO added the enhancement label Dec 16, 2016

dcodeIO added a commit that referenced this issue Dec 16, 2016

@dcodeIO

This comment has been minimized.

Owner

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

This comment has been minimized.

vgoloviznin commented Dec 16, 2016

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

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 16, 2016

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

@vgoloviznin

This comment has been minimized.

vgoloviznin commented Dec 16, 2016

Awesome, thanks for the quick fix!

I will check during the weekend for our definition

@dcodeIO

This comment has been minimized.

Owner

dcodeIO commented Dec 16, 2016

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

@dcodeIO dcodeIO closed this Dec 16, 2016

@thirstyfish

This comment has been minimized.

thirstyfish commented Feb 19, 2017

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

This comment has been minimized.

Owner

dcodeIO commented Feb 19, 2017

Yes: Root#load

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

This comment has been minimized.

thirstyfish commented Feb 27, 2017

Great, thanks for your help!

@samkeke

This comment has been minimized.

samkeke commented Jan 23, 2018

Thank you help,

I finally found the answer

@rahulverma

This comment has been minimized.

rahulverma commented Oct 30, 2018

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