From f9a9191e1116df5127fa31ddd3655594c0071602 Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Tue, 8 Nov 2022 14:35:16 -0800 Subject: [PATCH] fix(gengapic): document client/bidi streaming unsupported in REST (#1181) --- internal/gengapic/gengapic.go | 3 +++ internal/gengapic/gengapic_test.go | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/gengapic/gengapic.go b/internal/gengapic/gengapic.go index ea961d62..0c65309e 100644 --- a/internal/gengapic/gengapic.go +++ b/internal/gengapic/gengapic.go @@ -479,6 +479,9 @@ func (g *generator) methodDoc(m *descriptor.MethodDescriptorProto) { return } + if containsTransport(g.opts.transports, rest) && m.GetClientStreaming() { + com = fmt.Sprintf("%s\n\nThis method is not supported for the REST transport.", com) + } // If the method is marked as deprecated and there is no comment, then add default deprecation comment. // If the method has a comment but it does not include a deprecation notice, then append a default deprecation notice. // If the method includes a deprecation notice at the beginning of the comment, prepend a comment stating the method is deprecated and use the included deprecation notice. diff --git a/internal/gengapic/gengapic_test.go b/internal/gengapic/gengapic_test.go index 2015960a..fc422f10 100644 --- a/internal/gengapic/gengapic_test.go +++ b/internal/gengapic/gengapic_test.go @@ -564,8 +564,9 @@ func TestMethodDoc(t *testing.T) { } for _, tst := range []struct { - in, want string - deprecated bool + in, want string + clientStreaming, deprecated bool + opts options }{ { in: "", @@ -595,11 +596,19 @@ func TestMethodDoc(t *testing.T) { want: "// MyMethod is deprecated.\n//\n// Deprecated: MyMethod may be removed in a future version.\n", deprecated: true, }, + { + in: "Does client streaming stuff.\n It also does other stuffs.", + want: "// MyMethod does client streaming stuff.\n// It also does other stuffs.\n//\n// This method is not supported for the REST transport.\n", + clientStreaming: true, + opts: options{transports: []transport{rest}}, + }, } { + g.opts = &tst.opts g.comments[m] = tst.in m.Options = &descriptor.MethodOptions{ Deprecated: proto.Bool(tst.deprecated), } + m.ClientStreaming = proto.Bool(tst.clientStreaming) g.pt.Reset() g.methodDoc(m) if diff := cmp.Diff(g.pt.String(), tst.want); diff != "" {