@@ -142,8 +142,11 @@ public static GapicContext parse(CodeGeneratorRequest request) {
142
142
Map <String , ResourceName > resourceNames = parseResourceNames (request );
143
143
messages = updateResourceNamesInMessages (messages , resourceNames .values ());
144
144
145
- // Contains only resource names that are actually used. That is, resource name definitions
146
- // or references that are simply defined, but not used, will not have corresponding Java helper
145
+ // Contains only resource names that are actually used. Usage refers to the presence of a
146
+ // request message's field in an RPC's method_signature annotation. That is, resource name
147
+ // definitions
148
+ // or references that are simply defined, but not used in such a manner, will not have
149
+ // corresponding Java helper
147
150
// classes generated.
148
151
Set <ResourceName > outputArgResourceNames = new HashSet <>();
149
152
List <Service > mixinServices = new ArrayList <>();
@@ -160,6 +163,37 @@ public static GapicContext parse(CodeGeneratorRequest request) {
160
163
transport );
161
164
162
165
Preconditions .checkState (!services .isEmpty (), "No services found to generate" );
166
+
167
+ // Temporary workaround for Ads, who still need these resource names.
168
+ if (services .get (0 ).protoPakkage ().startsWith ("google.ads.googleads.v" )) {
169
+ Function <ResourceName , String > typeNameFn =
170
+ r -> r .resourceTypeString ().substring (r .resourceTypeString ().indexOf ("/" ) + 1 );
171
+ Function <Set <ResourceName >, Set <String >> typeStringSetFn =
172
+ sr -> sr .stream ().map (r -> typeNameFn .apply (r )).collect (Collectors .toSet ());
173
+
174
+ // Include all resource names present in message types for backwards-compatibility with the
175
+ // monolith. In the future, this should be removed on a client library major semver update.
176
+ // Resolve type name collisions with the ones present in the method arguments.
177
+ final Set <String > typeStringSet = typeStringSetFn .apply (outputArgResourceNames );
178
+ outputArgResourceNames .addAll (
179
+ resourceNames .values ().stream ()
180
+ .filter (r -> r .hasParentMessageName () && !typeStringSet .contains (typeNameFn .apply (r )))
181
+ .collect (Collectors .toSet ()));
182
+
183
+ String servicePackage = services .get (0 ).pakkage ();
184
+ Map <String , ResourceName > patternsToResourceNames =
185
+ ResourceParserHelpers .createPatternResourceNameMap (resourceNames );
186
+ for (ResourceReference resourceReference : outputResourceReferencesSeen ) {
187
+ final Set <String > interimTypeStringSet = typeStringSetFn .apply (outputArgResourceNames );
188
+ outputArgResourceNames .addAll (
189
+ ResourceReferenceParser .parseResourceNames (
190
+ resourceReference , servicePackage , null , resourceNames , patternsToResourceNames )
191
+ .stream ()
192
+ .filter (r -> !interimTypeStringSet .contains (typeNameFn .apply (r )))
193
+ .collect (Collectors .toSet ()));
194
+ }
195
+ }
196
+
163
197
return GapicContext .builder ()
164
198
.setServices (services )
165
199
.setMixinServices (mixinServices )
0 commit comments