Skip to content

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

@MicroOps-cn

Description

@MicroOps-cn

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,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions