From eb6fb9f7091825f34555fb65ef79035180387540 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:14:00 -0500 Subject: [PATCH] fix: add missing cast for proto optionals (#1557) Related: https://github.com/googleapis/gapic-generator-go/pull/1541 --- internal/gengapic/paging.go | 4 ++-- internal/gengapic/testdata/method_GetManyThingsOptional.want | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/gengapic/paging.go b/internal/gengapic/paging.go index 353d8ea52..241551cdb 100644 --- a/internal/gengapic/paging.go +++ b/internal/gengapic/paging.go @@ -332,7 +332,7 @@ func internalPageSizeSetter(p func(s string, a ...interface{}), pageSize *descri switch pageSize.GetType() { case descriptorpb.FieldDescriptorProto_TYPE_INT32: if pageSize.GetProto3Optional() { - p("req.%s = proto.Int32(%s)", cName, setVal) + p("req.%s = proto.Int32(int32(%s))", cName, setVal) } else { if setVal != "math.MaxInt32" { setVal = fmt.Sprintf("int32(%s)", setVal) @@ -341,7 +341,7 @@ func internalPageSizeSetter(p func(s string, a ...interface{}), pageSize *descri } case descriptorpb.FieldDescriptorProto_TYPE_UINT32: if pageSize.GetProto3Optional() { - p("req.%s = proto.UInt32(%s)", cName, setVal) + p("req.%s = proto.UInt32(uint32(%s))", cName, setVal) } else { p("req.%s = uint32(%s)", cName, setVal) } diff --git a/internal/gengapic/testdata/method_GetManyThingsOptional.want b/internal/gengapic/testdata/method_GetManyThingsOptional.want index e913744aa..7d2761f76 100644 --- a/internal/gengapic/testdata/method_GetManyThingsOptional.want +++ b/internal/gengapic/testdata/method_GetManyThingsOptional.want @@ -12,9 +12,9 @@ func (c *fooGRPCClient) GetManyThingsOptional(ctx context.Context, req *mypackag req.PageToken = proto.String(pageToken) } if pageSize > math.MaxInt32 { - req.PageSize = proto.Int32(math.MaxInt32) + req.PageSize = proto.Int32(int32(math.MaxInt32)) } else if pageSize != 0 { - req.PageSize = proto.Int32(pageSize) + req.PageSize = proto.Int32(int32(pageSize)) } err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { var err error