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

feat: oneof=unions-value to use the same field name for oneof cases #1062

Merged
merged 4 commits into from
Jun 15, 2024

Conversation

bhollis
Copy link
Contributor

@bhollis bhollis commented Jun 14, 2024

Fixes #1060.

This adds a new oneof=unions-value option that changes how union oneof code is generated. Instead of each case having a field named the same as the $case, each of them has the same field, called value. This should simplify writing generic code that can handle multiple cases at once.

I chose to make it another option for oneof= instead of a separate option since it's just another way of handling oneofs. I also updated the README but it may be a bit much, I'm happy to remove some stuff. I also presumptively suggest that this be the new recommended oneof option.

@@ -752,7 +752,7 @@ ts-protoc --ts_proto_out=./output -I=./protos ./protoc/*.proto
# Todo

- Support the string-based encoding of duration in `fromJSON`/`toJSON`
- Make `oneof=unions` the default behavior in 2.0
- Make `oneof=unions-value` the default behavior in 2.0
Copy link
Owner

Choose a reason for hiding this comment

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

Ah nice! I definitely agree this value field is better and should be the default.

We're in luck that a 2.x release is likely going to happen in the next ~month or so, via #1058, so we should plan on flipping this default over, and honestly probably just removing the option/old behavior all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great, feel free to ping me if you want help with that.

Copy link
Owner

Choose a reason for hiding this comment

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

Great! I'll ping you once Timo's PR lands as an 2.0.0 alpha and would be great to get this flipped over.

@stephenh
Copy link
Owner

This is great, thank you @bhollis !

@stephenh stephenh merged commit 7493090 into stephenh:main Jun 15, 2024
6 checks passed
stephenh pushed a commit that referenced this pull request Jun 15, 2024
# [1.180.0](v1.179.0...v1.180.0) (2024-06-15)

### Features

* oneof=unions-value to use the same field name for oneof cases ([#1062](#1062)) ([7493090](7493090)), closes [#1060](#1060)
@stephenh
Copy link
Owner

🎉 This PR is included in version 1.180.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 this pull request may close these issues.

Easier to use oneof=union generated code
2 participants