Merge pull request #55223 from mfojtik/fix-proto

Automatic merge from submit-queue (batch tested with PRs 56894, 56940, 55223, 56554, 54985). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix protobuf generator for aliases to repeated types

Currently if a type has an alias the generator will fail generating protobuf. This prevents the problem.

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-12-16 13:49:57 -08:00 committed by GitHub
commit 2ed402420b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -516,11 +516,14 @@ func memberTypeToProtobufField(locator ProtobufLocator, field *protoField, t *ty
log.Printf("failed to alias: %s %s: err %v", t.Name, t.Underlying.Name, err) log.Printf("failed to alias: %s %s: err %v", t.Name, t.Underlying.Name, err)
return err return err
} }
// If this is not an alias to a slice, cast to the alias
if !field.Repeated {
if field.Extras == nil { if field.Extras == nil {
field.Extras = make(map[string]string) field.Extras = make(map[string]string)
} }
field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name)) field.Extras["(gogoproto.casttype)"] = strconv.Quote(locator.CastTypeName(t.Name))
} }
}
case types.Slice: case types.Slice:
if t.Elem.Name.Name == "byte" && len(t.Elem.Name.Package) == 0 { if t.Elem.Name.Name == "byte" && len(t.Elem.Name.Package) == 0 {
field.Type = &types.Type{Name: types.Name{Name: "bytes"}, Kind: types.Protobuf} field.Type = &types.Type{Name: types.Name{Name: "bytes"}, Kind: types.Protobuf}