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 a794bf0d49..b46c94cc9d 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 @@ -65,6 +65,10 @@ public class Parser { private static final String COLON = ":"; private static final String DEFAULT_PORT = "443"; private static final String DOT = "."; + + private static final Set DUPE_SERVICE_CODEGEN_BLOCKLIST = + new HashSet<>(Arrays.asList("google.longrunning", "google.iam.v1")); + // Allow other parsers to access this. protected static final SourceCodeInfoParser SOURCE_CODE_INFO_PARSER = new SourceCodeInfoParser(); @@ -131,6 +135,26 @@ public static List parseServices( outputArgResourceNames)); } + // Prevent codegen for IAM or LRO if there are other services present, since that is an + // indicator that we are not generating a GAPIC client for IAM or LRO. + Set serviceProtoPackages = + services.stream().map(s -> s.protoPakkage()).collect(Collectors.toSet()); + boolean servicesContainBlocklistedApi = false; + for (String blocklistedPackage : DUPE_SERVICE_CODEGEN_BLOCKLIST) { + // It's very unlikely the blocklisted APIs will contain the other, or any other service. + if (serviceProtoPackages.contains(blocklistedPackage) && serviceProtoPackages.size() > 1) { + servicesContainBlocklistedApi = true; + break; + } + } + + if (servicesContainBlocklistedApi) { + services = + services.stream() + .filter(s -> !DUPE_SERVICE_CODEGEN_BLOCKLIST.contains(s.protoPakkage())) + .collect(Collectors.toList()); + } + return services; }