[feat] Option to generate enum with full prefix
vctqs1 opened this issue · comments
For example, the code below is generated from buf
:
/**
* @generated from enum usermgmt.common.ImportUserEventStatus
*/
export enum ImportUserEventStatus {
/**
* @generated from enum value: IMPORT_USER_EVENT_STATUS_WAITING = 0;
*/
WAITING = 0,
/**
* @generated from enum value: IMPORT_USER_EVENT_STATUS_FINISHED = 1;
*/
FINISHED = 1,
/**
* @generated from enum value: IMPORT_USER_EVENT_STATUS_FAILED = 2;
*/
FAILED = 2,
}
However, in the backend (BE) code, the definition is as follows:
enum ImportUserEventStatus{
IMPORT_USER_EVENT_STATUS_WAITING = 0;
IMPORT_USER_EVENT_STATUS_FINISHED = 1;
IMPORT_USER_EVENT_STATUS_FAILED = 2;
}
The question arises: Instead of generating and stripping out theprefix
, should we consider adding opts to generate with the full key, such asIMPORT_USER_EVENT_STATUS_FAILED
instead of justFAILED
?
This consideration is important because when storing data in the database, it uses the full name (IMPORT_USER_EVENT_STATUS_FAILED
) instead of the stripped-out version.
Using the full key ImportUserEventStatus[key]
in the code makes it easier for mapping between the number and key instead of using longer methods like proto3.getEnumType(ImportUserEventStatus).findName(<value>)
.
I also post my question in Slack before https://bufbuild.slack.com/archives/CRZ680FUH/p1699259433760749
Hi @vctqs1! This would be a good feature request to open in the protobuf-es repo, which generates the code in your example.
@smallsamantha Ah thank you. Sorry for the inconvenience