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 06058813f5..5ed2d7e28b 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 @@ -360,13 +360,14 @@ private static List createPagingStaticAssignExprs( Preconditions.checkState( field != null, String.format("Null field found for message %s", pagedResponseMessage.name())); - if (field.isRepeated()) { + if (field.isRepeated() && !field.isMap()) { // Field is currently a List-type. Preconditions.checkState( !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(); + break; } } Preconditions.checkNotNull( diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index ec7d6a83d5..43e7e7c435 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -364,9 +364,11 @@ static String sanitizeDefaultHost(String rawDefaultHost) { } private static List parseFields(Descriptor messageDescriptor) { - return messageDescriptor.getFields().stream() - .map(f -> parseField(f, messageDescriptor)) - .collect(Collectors.toList()); + List fields = new ArrayList<>(messageDescriptor.getFields()); + // Sort by ascending field index order. This is important for paged responses, where the first + // repeated type is taken. + fields.sort((f1, f2) -> f1.getIndex() - f2.getIndex()); + return fields.stream().map(f -> parseField(f, messageDescriptor)).collect(Collectors.toList()); } private static Field parseField(FieldDescriptor fieldDescriptor, Descriptor messageDescriptor) { diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 60a4ca6aa9..af5762b6e8 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -1,3 +1,8 @@ +load( + "@com_google_googleapis_imports//:imports.bzl", + java_gapic_library = "java_gapic_library2", +) + package(default_visibility = ["//visibility:public"]) #################################################### @@ -5,11 +10,6 @@ package(default_visibility = ["//visibility:public"]) #################################################### # These will eventually go away once more APIs in googleapis have been migrated to the microgenerator. -load( - "@com_google_googleapis_imports//:imports.bzl", - java_gapic_library = "java_gapic_library2", -) - java_gapic_library( name = "asset_java_gapic", srcs = ["@com_google_googleapis//google/cloud/asset/v1:asset_proto_with_info"],