From 023fed2baa2898fec0e0658963ae549eb2077971 Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Wed, 7 Dec 2022 13:05:55 -0800 Subject: [PATCH] fix(gengapic): extraneous protojson import (#1196) --- internal/gengapic/genrest.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/gengapic/genrest.go b/internal/gengapic/genrest.go index 6fbb96c10..8fbb9fd54 100644 --- a/internal/gengapic/genrest.go +++ b/internal/gengapic/genrest.go @@ -643,6 +643,7 @@ func (g *generator) serverStreamRESTCall(servName string, s *descriptor.ServiceD body = "bytes.NewReader(jsonReq)" g.imports[pbinfo.ImportSpec{Path: "bytes"}] = true + g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true } g.generateBaseURL(info, "return nil, err") @@ -683,7 +684,6 @@ func (g *generator) serverStreamRESTCall(servName string, s *descriptor.ServiceD p("") g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true // server-stream wrapper client p("// %s is the stream client used to consume the server stream created by", streamClient) @@ -1146,6 +1146,8 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto body = "bytes.NewReader(jsonReq)" g.imports[pbinfo.ImportSpec{Path: "bytes"}] = true + g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true + } g.generateBaseURL(info, "return nil, err") @@ -1155,6 +1157,8 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto g.appendCallOpts(m) if !isHTTPBodyMessage { p("unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}") + g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true + } p("resp := &%s.%s{}", outSpec.Name, outType.GetName()) p("e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {") @@ -1211,7 +1215,6 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto g.imports[pbinfo.ImportSpec{Path: "io/ioutil"}] = true g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/encoding/protojson"}] = true g.imports[inSpec] = true g.imports[outSpec] = true return nil