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

version 1.90.0 broke snakeToCamel=false functionality #423

Closed
SchroederChris opened this issue Dec 1, 2021 · 8 comments · Fixed by #429
Closed

version 1.90.0 broke snakeToCamel=false functionality #423

SchroederChris opened this issue Dec 1, 2021 · 8 comments · Fixed by #429
Labels

Comments

@SchroederChris
Copy link
Contributor

Hey, as you already discussed in #408, that PR introduced breaking changes when using snakeToCamel=false.

In our case, the json we're receiving contains snake_case properties, so all fromJSON methods accessing those properties are broken with the new version.

I'd very much appreciate getting back the old behavior as you suggested with the keys-and-json option.

@stephenh
Copy link
Owner

stephenh commented Dec 1, 2021

@SchroederChris thanks for reporting.

@ajaykarthikr or @SchroederChris , could either of you submit a PR for this?

I think changing the snakeToCamel: boolean to snakeToCamel: boolean | string and then supporting snakeToCamel=keys,json where if it's not "true" or "false" we split on ","?

So to the rest of the code generator, snakeToCamel would look like snakeToCamel: Array<"keys" | "json">, but we support the user setting true / false and then map those to true --> ["keys"] and false --> [] and then keys,json => ["keys", "json"].

@ajaykarthikr
Copy link
Collaborator

ajaykarthikr commented Dec 1, 2021

Ohhw, I think I got your general idea. But can you please clarify one thing? When there's json in snakeToCamel flag, should the json field names be camelCase or snake_case

@stephenh
Copy link
Owner

stephenh commented Dec 1, 2021

Oh right, snakeToCamel "with json in it" insinuates json would be camelized.

How about:

  • snakeToCamel=true (the default) --> ["keys", "json"]
  • snakeToCamel=false --> []
  • snakeToCamel=keys --> ["keys"], use camel cased message keys, but still snake case in to/from JSON
  • snakeToCamel=json --> ["json"], use proto3-spec camel casing in to/fromJSON, but still snake case in message keys
  • snakeToCamel=keys,json --> ["keys","json"]

I think the ^ would actually restore snakeToCamel=false to the previous behavior, which is that it meant neither message keys or json fields were camelized.

But, if a user wanted, they could use snake keys (i.e. Message.first_name) but json fields (so message: { firstName: ... } }), which is not something the can do today with just true / false.

And then whenever config.snakeToCamel.includes("json") we would use the jsonName from protobuf (which they've camelized for us), but if "json" is not in the list, we'd use the field name, which would restore the behavior @SchroederChris wants.

Does that sound good?

@SchroederChris
Copy link
Contributor Author

@stephenh I like that solution 👍 It allows for full flexibility and still keeps backwards compatibility.

@ajaykarthikr thank you for taking care of this! You're probably more familiar with it than me atm. as you just changed it recently while for me it's been several months at least 😃

@ajaykarthikr
Copy link
Collaborator

@stephenh Thanks for the detailed explanation. I add a PR soon.

Can you guys give me a day or two to fix this? 😅

@SchroederChris
Copy link
Contributor Author

@ajaykarthikr sure, take your time 🙂 For me this is not urgent at all - the older versions currently work just fine for us.

ajaykarthikr added a commit to ajaykarthikr/ts-proto that referenced this issue Dec 5, 2021
Changed `snakeToCamel: boolean` to `snakeToCamel: boolean | string`.
So that `snakeToCamel` would look like `snakeToCamel: Array<"keys" | "json">`.

So user can set true / false and then map those to true --> ["keys"] and false --> [] and then keys,json => ["keys", "json"]
resolves stephenh#423
stephenh pushed a commit that referenced this issue Dec 13, 2021
* fix: support mutliple options in snakeToCamel flag
Changed `snakeToCamel: boolean` to `snakeToCamel: boolean | string`.
So that `snakeToCamel` would look like `snakeToCamel: Array<"keys" | "json">`.

So user can set true / false and then map those to true --> ["keys"] and false --> [] and then keys,json => ["keys", "json"]
resolves #423

* docs: update ts_proto_opt usage in readme
stephenh pushed a commit that referenced this issue Dec 13, 2021
## [1.93.3](v1.93.2...v1.93.3) (2021-12-13)

### Bug Fixes

* support mutliple options in snakeToCamel flag  ([#429](#429)) ([cff6674](cff6674)), closes [#423](#423)
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 1.93.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SchroederChris
Copy link
Contributor Author

@ajaykarthikr @stephenh thanks guys!

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

Successfully merging a pull request may close this issue.

3 participants