Skip to content

Commit fcac803

Browse files
authored
gapic: fix empty libraryClient in metadata (#533)
Sometimes, when the `package` name matches the reduced service name (the proto Service name sans `"Service"` suffix), the generated client type is named `Client` as the `servName` variable is `""`. This accounts for that with the metadata generation.
1 parent 793876b commit fcac803

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

internal/gengapic/metadata.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ func (g *generator) addMetadataServiceForTransport(service, transport, lib strin
3838
g.metadata.Services[service] = s
3939
}
4040

41+
// When the Service name matches the package name, the client is named just
42+
// "Client". We need to catch that.
43+
//
44+
// TODO(noahdietz): when REGAPIC is added we may need to special case based
45+
// on transport.
46+
if lib == "" {
47+
lib = "Client"
48+
}
49+
4150
s.Clients[transport] = &metadata.GapicMetadata_ServiceAsClient{
4251
LibraryClient: lib,
4352
Rpcs: make(map[string]*metadata.GapicMetadata_MethodList),

internal/gengapic/metadata_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,38 @@ func TestAddMetadataServiceForTransport(t *testing.T) {
7979
},
8080
},
8181
},
82+
{
83+
service: "LibraryService",
84+
lib: "",
85+
init: &metadatapb.GapicMetadata{
86+
Services: map[string]*metadatapb.GapicMetadata_ServiceForTransport{
87+
"LibraryService": {
88+
Clients: map[string]*metadatapb.GapicMetadata_ServiceAsClient{
89+
"rest": {
90+
LibraryClient: "LibraryServiceRestClient",
91+
Rpcs: make(map[string]*metadata.GapicMetadata_MethodList),
92+
},
93+
},
94+
},
95+
},
96+
},
97+
want: &metadatapb.GapicMetadata{
98+
Services: map[string]*metadatapb.GapicMetadata_ServiceForTransport{
99+
"LibraryService": {
100+
Clients: map[string]*metadatapb.GapicMetadata_ServiceAsClient{
101+
"grpc": {
102+
LibraryClient: "Client",
103+
Rpcs: make(map[string]*metadata.GapicMetadata_MethodList),
104+
},
105+
"rest": {
106+
LibraryClient: "LibraryServiceRestClient",
107+
Rpcs: make(map[string]*metadata.GapicMetadata_MethodList),
108+
},
109+
},
110+
},
111+
},
112+
},
113+
},
82114
} {
83115
g := generator{
84116
metadata: tst.init,

0 commit comments

Comments
 (0)