Skip to content

Commit

Permalink
[ggj][codegen] fix: sort message fields in asc. index order (#382)
Browse files Browse the repository at this point in the history
* fix: support LRO package.name annotations

* feat: add microgenerator rules for cloud/asset

* fix: update CircleCI

* fix: sort message fields in asc. index order

* fix: update parser test method sig order

* fix: update circleci config

* fix: linter
  • Loading branch information
miraleung authored Oct 10, 2020
1 parent 085393b commit 5f46bdc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,14 @@ private static List<Expr> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,11 @@ static String sanitizeDefaultHost(String rawDefaultHost) {
}

private static List<Field> parseFields(Descriptor messageDescriptor) {
return messageDescriptor.getFields().stream()
.map(f -> parseField(f, messageDescriptor))
.collect(Collectors.toList());
List<FieldDescriptor> 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) {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
load(
"@com_google_googleapis_imports//:imports.bzl",
java_gapic_library = "java_gapic_library2",
)

package(default_visibility = ["//visibility:public"])

####################################################
# API Library Rules
####################################################
# 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"],
Expand Down

0 comments on commit 5f46bdc

Please sign in to comment.