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

Define type-safe enums in Ruby generated code using Sorbet #9270

Closed
chnakamura opened this issue Nov 30, 2021 · 2 comments
Closed

Define type-safe enums in Ruby generated code using Sorbet #9270

chnakamura opened this issue Nov 30, 2021 · 2 comments
Labels

Comments

@chnakamura
Copy link

What language does this apply to? Ruby
If it's a proto syntax change, is it for proto2 or proto3? NA
If it's about generated code change, what programming language? Ruby

Describe the problem you are trying to solve.
When used ruby code generated from a protobuf with an enum definition, the enum field is not type-safe because enum values are handled as symbols or integers.

Describe the solution you'd like
Sorbet is a fast, powerful type checker designed for Ruby that is used in my project. I would like to be able to automatically generate an instance of the Sorbet typed enum class whose fields would match those defined in the protobuf. This would allow the enum field to be strictly typed, rather than a symbol or integer.

Describe alternatives you've considered
The alternative is to not have type safety on enum fields and instead continue passing them as symbols. This works fine, but having the guardrail of type-safety would still be preferred.

Additional context
Protobuf Ruby generated code docs
Sorbet Enums

@elharo
Copy link
Contributor

elharo commented Dec 1, 2021

I'm not familiar with Ruby. Is Sorbet an extra dependency? Would this be fully backwards and forwards compatible with existing code?

@elharo elharo added the ruby label Dec 1, 2021
@deannagarcia
Copy link
Member

The protobuf team prioritizes keeping a small set of dependencies, so adding this dependency is not something we want to pursue.

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

No branches or pull requests

3 participants