Skip to content

Commit 00c6ad6

Browse files
authored
[ggj][codegen] fix: generate param-less RPC Java methods for empty sigs (#575)
* fix: handle empty method_signature in parsing protos * fix: add google/type:type_java_proto as default test dep * fix: support singleton resource names in parsing and codegen * fix: generate param-less RPC Java methods for empty sigs * fix: merge master
1 parent d3fea22 commit 00c6ad6

File tree

11 files changed

+439
-45
lines changed

11 files changed

+439
-45
lines changed

src/main/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ private static List<MethodDefinition> createTestMethods(
424424
service,
425425
Collections.emptyList(),
426426
0,
427+
true,
427428
classMemberVarExprs,
428429
resourceNames,
429430
messageTypes));
@@ -444,6 +445,7 @@ private static List<MethodDefinition> createTestMethods(
444445
service,
445446
method.methodSignatures().get(i),
446447
i,
448+
false,
447449
classMemberVarExprs,
448450
resourceNames,
449451
messageTypes));
@@ -467,6 +469,7 @@ private static MethodDefinition createRpcTestMethod(
467469
Service service,
468470
List<MethodArgument> methodSignature,
469471
int variantIndex,
472+
boolean isRequestArg,
470473
Map<String, VariableExpr> classMemberVarExprs,
471474
Map<String, ResourceName> resourceNames,
472475
Map<String, Message> messageTypes) {
@@ -584,7 +587,6 @@ private static MethodDefinition createRpcTestMethod(
584587
methodStatements.add(EMPTY_LINE_STATEMENT);
585588

586589
// Construct the request or method arguments.
587-
boolean isRequestArg = methodSignature.isEmpty();
588590
VariableExpr requestVarExpr = null;
589591
Message requestMessage = null;
590592
List<VariableExpr> argExprs = new ArrayList<>();

src/main/java/com/google/api/generator/gapic/protoparser/MethodSignatureParser.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.common.collect.Lists;
2828
import com.google.protobuf.Descriptors.MethodDescriptor;
2929
import java.util.ArrayList;
30+
import java.util.Collections;
3031
import java.util.HashMap;
3132
import java.util.List;
3233
import java.util.Map;
@@ -61,6 +62,7 @@ public static List<List<MethodArgument>> parseMethodSignatures(
6162
// stringSigs: ["content,error", "content,error,info"].
6263
for (String stringSig : stringSigs) {
6364
if (Strings.isNullOrEmpty(stringSig)) {
65+
signatures.add(Collections.emptyList());
6466
continue;
6567
}
6668

src/test/java/com/google/api/generator/gapic/composer/goldens/EchoClient.golden

+124
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ public class EchoClient implements BackgroundResource {
143143
return operationsClient;
144144
}
145145

146+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
147+
/**
148+
* @param request The request object containing all of the parameters for the API call.
149+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
150+
*/
151+
public final EchoResponse echo() {
152+
EchoRequest request = EchoRequest.newBuilder().build();
153+
return echo(request);
154+
}
155+
146156
// AUTO-GENERATED DOCUMENTATION AND METHOD.
147157
/**
148158
* @param parent
@@ -280,6 +290,38 @@ public class EchoClient implements BackgroundResource {
280290
return stub.pagedExpandCallable();
281291
}
282292

293+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
294+
/**
295+
* @param request The request object containing all of the parameters for the API call.
296+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
297+
*/
298+
public final SimplePagedExpandPagedResponse simplePagedExpand() {
299+
PagedExpandRequest request = PagedExpandRequest.newBuilder().build();
300+
return simplePagedExpand(request);
301+
}
302+
303+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
304+
/**
305+
* @param request The request object containing all of the parameters for the API call.
306+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
307+
*/
308+
public final SimplePagedExpandPagedResponse simplePagedExpand(PagedExpandRequest request) {
309+
return simplePagedExpandPagedCallable().call(request);
310+
}
311+
312+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
313+
/** Sample code: */
314+
public final UnaryCallable<PagedExpandRequest, SimplePagedExpandPagedResponse>
315+
simplePagedExpandPagedCallable() {
316+
return stub.simplePagedExpandPagedCallable();
317+
}
318+
319+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
320+
/** Sample code: */
321+
public final UnaryCallable<PagedExpandRequest, PagedExpandResponse> simplePagedExpandCallable() {
322+
return stub.simplePagedExpandCallable();
323+
}
324+
283325
// AUTO-GENERATED DOCUMENTATION AND METHOD.
284326
/**
285327
* @param ttl
@@ -445,4 +487,86 @@ public class EchoClient implements BackgroundResource {
445487
return new PagedExpandFixedSizeCollection(pages, collectionSize);
446488
}
447489
}
490+
491+
public static class SimplePagedExpandPagedResponse
492+
extends AbstractPagedListResponse<
493+
PagedExpandRequest,
494+
PagedExpandResponse,
495+
EchoResponse,
496+
SimplePagedExpandPage,
497+
SimplePagedExpandFixedSizeCollection> {
498+
499+
public static ApiFuture<SimplePagedExpandPagedResponse> createAsync(
500+
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
501+
ApiFuture<PagedExpandResponse> futureResponse) {
502+
ApiFuture<SimplePagedExpandPage> futurePage =
503+
SimplePagedExpandPage.createEmptyPage().createPageAsync(context, futureResponse);
504+
return ApiFutures.transform(
505+
futurePage,
506+
new ApiFunction<SimplePagedExpandPage, SimplePagedExpandPagedResponse>() {
507+
@Override
508+
public SimplePagedExpandPagedResponse apply(SimplePagedExpandPage input) {
509+
return new SimplePagedExpandPagedResponse(input);
510+
}
511+
},
512+
MoreExecutors.directExecutor());
513+
}
514+
515+
private SimplePagedExpandPagedResponse(SimplePagedExpandPage page) {
516+
super(page, SimplePagedExpandFixedSizeCollection.createEmptyCollection());
517+
}
518+
}
519+
520+
public static class SimplePagedExpandPage
521+
extends AbstractPage<
522+
PagedExpandRequest, PagedExpandResponse, EchoResponse, SimplePagedExpandPage> {
523+
524+
private SimplePagedExpandPage(
525+
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
526+
PagedExpandResponse response) {
527+
super(context, response);
528+
}
529+
530+
private static SimplePagedExpandPage createEmptyPage() {
531+
return new SimplePagedExpandPage(null, null);
532+
}
533+
534+
@Override
535+
protected SimplePagedExpandPage createPage(
536+
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
537+
PagedExpandResponse response) {
538+
return new SimplePagedExpandPage(context, response);
539+
}
540+
541+
@Override
542+
public ApiFuture<SimplePagedExpandPage> createPageAsync(
543+
PageContext<PagedExpandRequest, PagedExpandResponse, EchoResponse> context,
544+
ApiFuture<PagedExpandResponse> futureResponse) {
545+
return super.createPageAsync(context, futureResponse);
546+
}
547+
}
548+
549+
public static class SimplePagedExpandFixedSizeCollection
550+
extends AbstractFixedSizeCollection<
551+
PagedExpandRequest,
552+
PagedExpandResponse,
553+
EchoResponse,
554+
SimplePagedExpandPage,
555+
SimplePagedExpandFixedSizeCollection> {
556+
557+
private SimplePagedExpandFixedSizeCollection(
558+
List<SimplePagedExpandPage> pages, int collectionSize) {
559+
super(pages, collectionSize);
560+
}
561+
562+
private static SimplePagedExpandFixedSizeCollection createEmptyCollection() {
563+
return new SimplePagedExpandFixedSizeCollection(null, 0);
564+
}
565+
566+
@Override
567+
protected SimplePagedExpandFixedSizeCollection createCollection(
568+
List<SimplePagedExpandPage> pages, int collectionSize) {
569+
return new SimplePagedExpandFixedSizeCollection(pages, collectionSize);
570+
}
571+
}
448572
}

0 commit comments

Comments
 (0)