Skip to content

Commit e0dd265

Browse files
committed
UPSTREAM: 55223: Fix protobuf generator for aliases to repeated types
1 parent d84ed50 commit e0dd265

File tree

1 file changed

+6
-3
lines changed
  • staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf

1 file changed

+6
-3
lines changed

staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,13 @@ func memberTypeToProtobufField(locator ProtobufLocator, field *protoField, t *ty
513513
log.Printf("failed to alias: %s %s: err %v", t.Name, t.Underlying.Name, err)
514514
return err
515515
}
516-
if field.Extras == nil {
517-
field.Extras = make(map[string]string)
516+
// If this is not an alias to a slice, cast to the alias
517+
if !field.Repeated {
518+
if field.Extras == nil {
519+
field.Extras = make(map[string]string)
520+
}
521+
field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name))
518522
}
519-
field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name))
520523
}
521524
case types.Slice:
522525
if t.Elem.Name.Name == "byte" && len(t.Elem.Name.Package) == 0 {

0 commit comments

Comments
 (0)