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

How to customize the name of an enumeration value, using the extension enumvalue_customname seems unable to complete. #756

Open
MicroOps-cn opened this issue Jul 15, 2022 · 0 comments

Comments

@MicroOps-cn
Copy link

This is the official test case:

enum MyEnum {
option (gogoproto.enum_customname) = "MyCustomEnum";
// The following field will take on the custom name and the prefix, joined
// by an underscore.
A = 0 [(gogoproto.enumvalue_customname) = "MyBetterNameA"];
B = 1; // Should be MyCustomEnum_B
}

const (
// The following field will take on the custom name and the prefix, joined
// by an underscore.
MyCustomEnum_MyBetterNameA MyCustomEnum = 0
MyCustomEnum_B MyCustomEnum = 1
)
var MyCustomEnum_name = map[int32]string{
0: "A",
1: "B",
}
var MyCustomEnum_value = map[string]int32{
"A": 0,
"B": 1,
}

In the above example, line 43 in the "enumcustomname.proto" file uses the "enumvalue_customname" extension to customize the name of the enumeration value. In the 34th page of "enumcustomname.pb.go", the variable name is the name of a custom enumeration value. However, lines 39 and 44 have not been replaced with custom enumeration names.
But I think the generated code should be like this:

const (
	// The following field will take on the custom name and the prefix, joined
	// by an underscore.
	MyCustomEnum_MyBetterNameA MyCustomEnum = 0
	MyCustomEnum_B             MyCustomEnum = 1
)

var MyCustomEnum_name = map[int32]string{
	0: "MyBetterNameA",
	1: "B",
}

var MyCustomEnum_value = map[string]int32{
	"MyBetterNameA": 0,
	"B": 1,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant