diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go index 8593aa311..c918fd140 100644 --- a/encoding/protobuf/parse.go +++ b/encoding/protobuf/parse.go @@ -582,6 +582,13 @@ func (p *protoConverter) enum(x *proto.Enum) { } p.file.Decls = append(p.file.Decls, enum, d) + numEnums := 0 + for _, v := range x.Elements { + if _, ok := v.(*proto.EnumField); ok { + numEnums++ + } + } + // The line comments for an enum field need to attach after the '|', which // is only known at the next iteration. var lastComment *proto.Comment @@ -601,7 +608,10 @@ func (p *protoConverter) enum(x *proto.Enum) { var e ast.Expr = value // Make the first value the default value. if i == 0 { - e = &ast.UnaryExpr{OpPos: newline, Op: token.MUL, X: value} + e = value + if numEnums > 1 { + e = &ast.UnaryExpr{OpPos: newline, Op: token.MUL, X: value} + } } else { value.ValuePos = newline } diff --git a/encoding/protobuf/testdata/client_config.proto.out.cue b/encoding/protobuf/testdata/client_config.proto.out.cue index efa1f4027..66ec87a91 100644 --- a/encoding/protobuf/testdata/client_config.proto.out.cue +++ b/encoding/protobuf/testdata/client_config.proto.out.cue @@ -42,19 +42,13 @@ NetworkFailPolicy: { maxRetryWait?: time.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait) } -// Describes the policy. +// Example of single-value enum. NetworkFailPolicy_FailPolicy: // If network connection fails, request is allowed and delivered to the // service. - *"FAIL_OPEN" | + "FAIL_OPEN" - // If network connection fails, request is rejected. - "FAIL_CLOSE" - -NetworkFailPolicy_FailPolicy_value: { - FAIL_OPEN: 0 - FAIL_CLOSE: 1 -} +NetworkFailPolicy_FailPolicy_value FAIL_OPEN: 0 // Defines the per-service client configuration. ServiceConfig: { diff --git a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config.proto b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config.proto index a2296990f..c54074592 100644 --- a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config.proto +++ b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config.proto @@ -37,14 +37,12 @@ option (gogoproto.stable_marshaler_all) = true; // Specifies the behavior when the client is unable to connect to Mixer. message NetworkFailPolicy { - // Describes the policy. + + // Example of single-value enum. enum FailPolicy { // If network connection fails, request is allowed and delivered to the // service. FAIL_OPEN = 0; - - // If network connection fails, request is rejected. - FAIL_CLOSE = 1; } // Specifies the behavior when the client is unable to connect to Mixer. diff --git a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config_proto_gen.cue b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config_proto_gen.cue index 2f4bf6493..8471bc5ce 100644 --- a/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config_proto_gen.cue +++ b/encoding/protobuf/testdata/istio.io/api/mixer/v1/config/client/client_config_proto_gen.cue @@ -41,19 +41,13 @@ NetworkFailPolicy: { maxRetryWait?: time.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait) } -// Describes the policy. +// Example of single-value enum. NetworkFailPolicy_FailPolicy: // If network connection fails, request is allowed and delivered to the // service. - *"FAIL_OPEN" | + "FAIL_OPEN" - // If network connection fails, request is rejected. - "FAIL_CLOSE" - -NetworkFailPolicy_FailPolicy_value: { - "FAIL_OPEN": 0 - "FAIL_CLOSE": 1 -} +NetworkFailPolicy_FailPolicy_value "FAIL_OPEN": 0 // Defines the per-service client configuration. ServiceConfig: {