|
36 | 36 | import java.util.List;
|
37 | 37 | import java.util.Map;
|
38 | 38 | import java.util.Map.Entry;
|
| 39 | +import java.util.Objects; |
39 | 40 | import javax.annotation.Nullable;
|
40 | 41 |
|
41 | 42 | /**
|
@@ -118,7 +119,6 @@ static GapicInterfaceConfig createInterfaceConfig(
|
118 | 119 |
|
119 | 120 | RetryCodesConfig retryCodesConfig =
|
120 | 121 | RetryCodesConfig.create(
|
121 |
| - diagCollector, |
122 | 122 | interfaceConfigProto,
|
123 | 123 | new ArrayList<>(interfaceInput.getMethodsToGenerate().keySet()),
|
124 | 124 | protoParser);
|
@@ -164,19 +164,32 @@ static GapicInterfaceConfig createInterfaceConfig(
|
164 | 164 | }
|
165 | 165 |
|
166 | 166 | ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
|
167 |
| - for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) { |
168 |
| - String entityName = collectionConfigProto.getEntityName(); |
169 |
| - ResourceNameConfig resourceName = resourceNameConfigs.get(entityName); |
170 |
| - if (!(resourceName instanceof SingleResourceNameConfig)) { |
171 |
| - diagCollector.addDiag( |
172 |
| - Diag.error( |
173 |
| - SimpleLocation.TOPLEVEL, |
174 |
| - "Inconsistent configuration - single resource name %s specified for interface, " |
175 |
| - + " but was not found in GapicProductConfig configuration.", |
176 |
| - entityName)); |
177 |
| - return null; |
| 167 | + if (protoParser.isProtoAnnotationsEnabled()) { |
| 168 | + resourceNameConfigs |
| 169 | + .values() |
| 170 | + .stream() |
| 171 | + .filter( |
| 172 | + r -> |
| 173 | + r.getResourceNameType() == ResourceNameType.SINGLE |
| 174 | + && Objects.equals(r.getAssignedProtoFile(), apiInterface.getFile())) |
| 175 | + .map(r -> (SingleResourceNameConfig) r) |
| 176 | + .forEach(resourcesBuilder::add); |
| 177 | + } else { |
| 178 | + for (CollectionConfigProto collectionConfigProto : |
| 179 | + interfaceConfigProto.getCollectionsList()) { |
| 180 | + String entityName = collectionConfigProto.getEntityName(); |
| 181 | + ResourceNameConfig resourceName = resourceNameConfigs.get(entityName); |
| 182 | + if (!(resourceName instanceof SingleResourceNameConfig)) { |
| 183 | + diagCollector.addDiag( |
| 184 | + Diag.error( |
| 185 | + SimpleLocation.TOPLEVEL, |
| 186 | + "Inconsistent configuration - single resource name %s specified for interface, " |
| 187 | + + " but was not found in GapicProductConfig configuration.", |
| 188 | + entityName)); |
| 189 | + return null; |
| 190 | + } |
| 191 | + resourcesBuilder.add((SingleResourceNameConfig) resourceName); |
178 | 192 | }
|
179 |
| - resourcesBuilder.add((SingleResourceNameConfig) resourceName); |
180 | 193 | }
|
181 | 194 | ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
|
182 | 195 |
|
|
0 commit comments