Skip to content

Commit c680367

Browse files
authored
Fix generated protobuf for derived enum value being used as list key. (#861)
Currently the enum is being output but it should just use the global name that's already generated. Added coverage.
1 parent cd1444d commit c680367

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

protogen/protogen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,10 +1117,7 @@ func genListKeyProto(listPackage string, listName string, args *protoDefinitionA
11171117
enum = args.ir.Enums[scalarType.EnumeratedYANGTypeKey]
11181118
}
11191119
switch {
1120-
case scalarType.IsEnumeratedValue && enum.Kind == ygen.IdentityType:
1121-
km.Imports = append(km.Imports, importPath(args.cfg.baseImportPath, args.cfg.basePackageName, args.cfg.enumPackageName))
1122-
fd.Type = scalarType.NativeType
1123-
case scalarType.IsEnumeratedValue:
1120+
case scalarType.IsEnumeratedValue && enum.Kind == ygen.SimpleEnumerationType:
11241121
// list keys must be leafs and not leaf-lists.
11251122
e, err := genProtoEnum(enum, args.cfg.annotateEnumNames, true)
11261123
if err != nil {
@@ -1129,6 +1126,9 @@ func genListKeyProto(listPackage string, listName string, args *protoDefinitionA
11291126
tn := genutil.MakeNameUnique(scalarType.NativeType, definedFieldNames)
11301127
fd.Type = tn
11311128
km.Enums[tn] = e
1129+
case scalarType.IsEnumeratedValue:
1130+
km.Imports = append(km.Imports, importPath(args.cfg.baseImportPath, args.cfg.basePackageName, args.cfg.enumPackageName))
1131+
fd.Type = scalarType.NativeType
11321132
case scalarType.UnionTypes != nil:
11331133
fd.IsOneOf = true
11341134
path := kf.YANGDetails.LeafrefTargetPath

protogen/testdata/proto/proto-test-c.proto-test-c.elists.elist.formatted-txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ syntax = "proto3";
88
package openconfig.proto_test_c.elists.elist;
99

1010
import "github.com/openconfig/ygot/proto/ywrapper/ywrapper.proto";
11+
import "openconfig/enums/enums.proto";
1112

1213
option go_package = "github.com/foo/baz/openconfig/proto_test_c/elists/elist";
1314

@@ -21,6 +22,7 @@ message Config {
2122
}
2223
ywrapper.StringValue non_key = 460983769;
2324
One one = 441760514;
25+
openconfig.enums.ProtoTestCEnumWithDefault three = 174447098;
2426
ywrapper.StringValue two = 294851988;
2527
}
2628

@@ -34,5 +36,6 @@ message State {
3436
}
3537
ywrapper.StringValue non_key = 139458606;
3638
One one = 199644645;
39+
openconfig.enums.ProtoTestCEnumWithDefault three = 20703553;
3740
ywrapper.StringValue two = 346656131;
3841
}

protogen/testdata/proto/proto-test-c.proto-test-c.formatted-txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ syntax = "proto3";
77

88
package openconfig.proto_test_c;
99

10+
import "openconfig/enums/enums.proto";
1011
import "openconfig/proto_test_c/elists/elists.proto";
1112
import "openconfig/proto_test_c/entity/entity.proto";
1213

@@ -21,8 +22,9 @@ message ElistKey {
2122
ONE_E42 = 43;
2223
}
2324
One one = 1;
24-
string two = 2;
25-
elists.Elist elist = 3;
25+
openconfig.enums.ProtoTestCEnumWithDefault three = 2;
26+
string two = 3;
27+
elists.Elist elist = 4;
2628
}
2729

2830
// Elists represents the /proto-test-c/elists YANG schema element.

protogen/testdata/proto/proto-test-c.yang

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ module proto-test-c {
7474
type string;
7575
}
7676

77+
leaf three {
78+
type enum-with-default;
79+
}
80+
7781
leaf non-key {
7882
type string;
7983
}
8084
}
8185

8286
container elists {
8387
list elist {
84-
key "one two";
88+
key "one two three";
8589

8690
leaf one {
8791
type leafref {
@@ -95,6 +99,12 @@ module proto-test-c {
9599
}
96100
}
97101

102+
leaf three {
103+
type leafref {
104+
path "../config/three";
105+
}
106+
}
107+
98108
container config {
99109
uses elist-cfg;
100110
}

0 commit comments

Comments
 (0)