Support Enum / Enum value options
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.
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.