Skip to content

Commit

Permalink
[ggj][protos] fix: prevent descension into map types in nested messag…
Browse files Browse the repository at this point in the history
…e parsing (#426)

* fix: support non-name fields with res-refs in resname def parsing

* fix: add workaround for missing default_host and oauth_scopes annotation

* [ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (#396)

* goldens update bazel rules

* clean up

* [ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (#397)

* goldens update bazel rules

* clean up

* goldens update rule for asset API

* update goldens

* [ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (#396)

* goldens update bazel rules

* clean up

* [ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (#397)

* goldens update bazel rules

* clean up

* goldens update rule for asset API

* update goldens

* [ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (#396)

* goldens update bazel rules

* clean up

* [ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (#397)

* goldens update bazel rules

* clean up

* goldens update rule for asset API

* update goldens

* fix: clarify LRO parsing error messages

* feat: support deeply-nested types in AST and proto message parsing

* fix: prevent resname tokens from matching subcomponents

* fix: use TypeParser for proto message parsing

* fix: merge master

* fix: use generic types in field instantiation in ServiceClientTest

* fix: prevent descension into map types in nested message parsing

* fix: merge master

* fix: merge master

* fix: merge master

* fix: merge master

Co-authored-by: Xiaozhen Liu <[email protected]>
  • Loading branch information
miraleung and xiaozhenliu-gg5 authored Oct 31, 2020
1 parent 080aa25 commit 6993a34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ private static Map<String, Message> parseMessages(
String messageName = messageDescriptor.getName();
if (!messageDescriptor.getNestedTypes().isEmpty()) {
for (Descriptor nestedMessage : messageDescriptor.getNestedTypes()) {
if (isMapType(nestedMessage)) {
continue;
}
outerNestedTypes.add(messageName);
messages.putAll(parseMessages(nestedMessage, outerNestedTypes));
}
Expand All @@ -248,6 +251,16 @@ private static Map<String, Message> parseMessages(
return messages;
}

private static boolean isMapType(Descriptor messageDescriptor) {
List<String> fieldNames =
messageDescriptor.getFields().stream().map(f -> f.getName()).collect(Collectors.toList());
// Ends in "Entry" and has exactly two fields, named "key" and "value".
return messageDescriptor.getName().endsWith("Entry")
&& fieldNames.size() == 2
&& fieldNames.get(0).equals("key")
&& fieldNames.get(1).equals("value");
}

/**
* Populates ResourceName objects in Message POJOs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public SourceCodeInfoLocation getLocation(FieldDescriptor field) {
if (!file.toProto().hasSourceCodeInfo()) {
return null;
}
return SourceCodeInfoLocation.create(getLocation(file, buildPath(field)));
Location fieldLocation = getLocation(file, buildPath(field));
return SourceCodeInfoLocation.create(fieldLocation);
}

/** Gets the location of a service, if available. */
Expand Down
1 change: 1 addition & 0 deletions test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ java_gapic_library(
],
)

# Logging API
java_gapic_library(
name = "logging_java_gapic",
srcs = ["@com_google_googleapis//google/logging/v2:logging_proto_with_info"],
Expand Down

0 comments on commit 6993a34

Please sign in to comment.