diff --git a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java index a2a509fb3e..fe8456bd00 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposer.java @@ -350,6 +350,7 @@ private static List createPagingStaticAssignExprs( "No method found for message type %s for method %s among %s", pagedResponseMessageKey, method.name(), messageTypes.keySet())); TypeNode repeatedResponseType = null; + String repeatedFieldName = null; for (Field field : pagedResponseMessage.fields()) { Preconditions.checkState( field != null, @@ -360,6 +361,7 @@ private static List createPagingStaticAssignExprs( !field.type().reference().generics().isEmpty(), String.format("No generics found for field reference %s", field.type().reference())); repeatedResponseType = TypeNode.withReference(field.type().reference().generics().get(0)); + repeatedFieldName = field.name(); } } Preconditions.checkNotNull( @@ -387,7 +389,12 @@ private static List createPagingStaticAssignExprs( descExprs.add( createPagedListDescriptorAssignExpr( - pagedListDescVarExpr, method, repeatedResponseType, types)); + pagedListDescVarExpr, + method, + repeatedResponseType, + repeatedFieldName, + messageTypes, + types)); factoryExprs.add( createPagedListResponseFactoryAssignExpr( pagedListDescVarExpr, method, repeatedResponseType, types)); @@ -401,6 +408,8 @@ private static Expr createPagedListDescriptorAssignExpr( VariableExpr pagedListDescVarExpr, Method method, TypeNode repeatedResponseType, + String repeatedFieldName, + Map messageTypes, Map types) { MethodDefinition.Builder methodStarterBuilder = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC); @@ -524,7 +533,8 @@ private static Expr createPagedListDescriptorAssignExpr( Expr getResponsesListExpr = MethodInvocationExpr.builder() .setExprReferenceExpr(payloadVarExpr) - .setMethodName("getResponsesList") + .setMethodName( + String.format("get%sList", JavaStyle.toUpperCamelCase(repeatedFieldName))) .setReturnType(returnType) .build(); Expr conditionExpr = diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java index 2696dcb7da..edd860b828 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java @@ -878,9 +878,9 @@ private static List parseServices( + " @Override\n" + " public Iterable extractResources(ListLogEntriesResponse" + " payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getEntriesList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getEntriesList();\n" + " }\n" + " };\n" + " private static final PagedListDescriptor<\n" @@ -928,9 +928,9 @@ private static List parseServices( + " @Override\n" + " public Iterable extractResources(\n" + " ListMonitoredResourceDescriptorsResponse payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getResourceDescriptorsList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getResourceDescriptorsList();\n" + " }\n" + " };\n" + " private static final PagedListDescriptor parseServices( + "\n" + " @Override\n" + " public Iterable extractResources(ListLogsResponse payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getLogNamesList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getLogNamesList();\n" + " }\n" + " };\n" + " private static final PagedListResponseFactory<\n" @@ -1617,9 +1617,9 @@ private static List parseServices( + "\n" + " @Override\n" + " public Iterable extractResources(ListTopicsResponse payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getTopicsList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getTopicsList();\n" + " }\n" + " };\n" + " private static final PagedListDescriptor<\n" @@ -1662,9 +1662,9 @@ private static List parseServices( + " @Override\n" + " public Iterable extractResources(ListTopicSubscriptionsResponse" + " payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getSubscriptionsList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getSubscriptionsList();\n" + " }\n" + " };\n" + " private static final PagedListDescriptor<\n" @@ -1704,9 +1704,9 @@ private static List parseServices( + " @Override\n" + " public Iterable extractResources(ListTopicSnapshotsResponse" + " payload) {\n" - + " return Objects.isNull(payload.getResponsesList())\n" + + " return Objects.isNull(payload.getSnapshotsList())\n" + " ? ImmutableList.of()\n" - + " : payload.getResponsesList();\n" + + " : payload.getSnapshotsList();\n" + " }\n" + " };\n" + " private static final PagedListResponseFactory<\n"