protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

enum values should have `json_name` pseudo-option just like fields

Open jhump opened this issue 7 years ago • 13 comments

Fields can be renamed, even when using JSON format, by setting json_name and ensuring that it never changes. This allows the field's name to change without impacting how it is serialized to/de-serialized from JSON.

Since enum values are also identified by name in the JSON format, they should have an analogous feature: a json_name pseudo-option, allowing the enum value's actual name to change while its JSON encoding remains the same.

I call the existing field json_name a "pseudo-option" because, though it uses the option syntax in proto source, it does not end up in the google.descriptor.FieldOptions message. Instead, it is promoted to a field of google.descriptor.FieldDescriptorProto. For symmetry, I would expect the enum value option to behave similarly, resulting in a new json_name field on google.descriptor.EnumValueDescriptorProto.

jhump avatar Feb 22 '18 16:02 jhump

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Jun 09 '24 10:06 github-actions[bot]

This is still relevant, can someone add the necessary labels so the bot won't come back here?

Fleshgrinder avatar Jun 09 '24 12:06 Fleshgrinder

I'm willing to bite the bullet on this, but I'd need some insights and discussion before putting a PR. Would you be available to share some context, @mkruskal-google ?

martelli avatar Jun 11 '24 13:06 martelli

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Sep 15 '24 10:09 github-actions[bot]

Active

Fleshgrinder avatar Sep 15 '24 12:09 Fleshgrinder

Any updates on this? Right now there's some incompatibility between proto convention through transcoding and graphql schema that forces you to match either side with the other for a consistent output, since the prefix is only a protobuf thing I think this feature would be a huge help.

alrz avatar Nov 09 '24 09:11 alrz

I ran into this limitation today. I think it would be really useful.

picatz avatar Jan 10 '25 01:01 picatz

HOw is this not a thing :D So many APIs all over use string values for enums (correctly or incorrectly)

kidpollo avatar Jan 15 '25 16:01 kidpollo

It would save so much pain and boilerplate code for custom conversions, how was not it handled it.

morinies avatar Jan 23 '25 07:01 morinies

I just ran into this issue myself, would be happy to help implement this in any way I can.

jeremija avatar Mar 11 '25 06:03 jeremija

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Sep 25 '25 10:09 github-actions[bot]

This is still a pain point.

Note: this is a useless comment to satiate the stalebot inactivity overlords

rhamzeh avatar Sep 25 '25 18:09 rhamzeh

I would love this kind of annotation

peczenyj avatar Nov 22 '25 05:11 peczenyj