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

Support Enum / Enum value options #37

Open
timostamm opened this issue Nov 26, 2020 · 1 comment · May be fixed by #562
Open

Support Enum / Enum value options #37

timostamm opened this issue Nov 26, 2020 · 1 comment · May be fixed by #562
Labels
enhancement New feature or request

Comments

@timostamm
Copy link
Owner

Protobuf has enum options. For example:

extend google.protobuf.EnumOptions {
    bool enum_opt_bool = 2001;
}

extend google.protobuf.EnumValueOptions {
    bool enum_value_opt_bool = 3001;
}


enum AnnotatedEnum {

    option (spec.enum_opt_bool) = true;

    UNSPECIFIED = 0;
    FOO = 1 [(spec.enum_value_opt_bool) = true];
}

These options should be made available in the generated code as JSON, just like field and service / method options already are.

Implementation is probably not straight-forward because there is no good place to put the data. One approach could be to use symbols to add the options to a hidden property on the TypeScript enum object.

@timostamm timostamm added the enhancement New feature or request label Nov 26, 2020
@timostamm timostamm mentioned this issue Dec 23, 2020
@nathansegers
Copy link

nathansegers commented Aug 23, 2023

I am unsure if my question fits for this comment, but I'll try anyways.

We have the request to get a Textual value from an enum into our Typescript code.

To clarify my comment, I'll give an example:

# myenum.ts
export const MyEnumTranslation: {id: MyEnum, name: string}[] = [
     { id: MyEnum.ANY, name: "Any" }, 
     { id: MyEnum.YES, name: "Yes" }, 
     { id: MyEnum.NO, name: "Nee" }, 
]
# myenum.proto
  enum MyEnum {
    ANY = 0;
    YES = 1;
    // @Translate: Nee
    NO = 2;
  }

In another plugin I was using, I managed to do this in a way by processing the Leading comments for each value.

But recently I found out the "EnumValueOptions" and wondered if this is fit for it.
Is it possible to use this in the way it was intended for the EnumValueOptions, or should I continue with my custom implementation?

FYI: I'm currently using the ".proto" files to simply generate the code in Typescript, C# and Python. This means that the Textual value is only used for visualisation purposes, and we keep the numeric Enumerations for the data transfer.

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

Successfully merging a pull request may close this issue.

2 participants