use of com.google.api.codegen.InterfaceConfigProto in project toolkit by googleapis.
the class GapicProductConfig method createDiscoGapicInterfaceConfigMap.
private static ImmutableMap<String, InterfaceConfig> createDiscoGapicInterfaceConfigMap(DiscoApiModel model, ConfigProto configProto, LanguageSettingsProto languageSettings, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, TargetLanguage language) {
ImmutableMap.Builder<String, InterfaceConfig> interfaceConfigMap = ImmutableMap.builder();
for (InterfaceConfigProto interfaceConfigProto : configProto.getInterfacesList()) {
String interfaceNameOverride = languageSettings.getInterfaceNamesMap().get(interfaceConfigProto.getName());
DiscoGapicInterfaceConfig interfaceConfig = DiscoGapicInterfaceConfig.createInterfaceConfig(model, language, interfaceConfigProto, interfaceNameOverride, messageConfigs, resourceNameConfigs);
if (interfaceConfig == null) {
continue;
}
interfaceConfigMap.put(interfaceConfigProto.getName(), interfaceConfig);
}
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
} else {
return interfaceConfigMap.build();
}
}
use of com.google.api.codegen.InterfaceConfigProto in project toolkit by googleapis.
the class GapicInterfaceConfig method createInterfaceConfig.
/**
* Creates an instance of GapicInterfaceConfig based on ConfigProto, linking up method
* configurations with specified methods in methodConfigMap. On errors, null will be returned, and
* diagnostics are reported to the model.
*/
@Nullable
static GapicInterfaceConfig createInterfaceConfig(DiagCollector diagCollector, TargetLanguage language, TransportProtocol transportProtocol, String defaultPackageName, GapicInterfaceInput interfaceInput, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ProtoParser protoParser, GrpcGapicRetryMapping grpcGapicRetryMapping) {
Interface apiInterface = interfaceInput.getInterface();
Map<Method, MethodConfigProto> methodsToGenerate = interfaceInput.getMethodsToGenerate();
InterfaceConfigProto interfaceConfigProto = interfaceInput.getInterfaceConfigProto();
RetryCodesConfig retryCodesConfig;
ImmutableMap<String, RetryParamsDefinitionProto> retrySettingsDefinition;
if (grpcGapicRetryMapping != null) {
// use the gRPC ServiceConfig retry mapping as the source
retryCodesConfig = RetryCodesConfig.create(grpcGapicRetryMapping, interfaceConfigProto.getName());
retrySettingsDefinition = RetryDefinitionsTransformer.createRetryDefinitionsFromGRPCServiceConfig(grpcGapicRetryMapping, interfaceConfigProto.getName());
} else {
// use the GAPIC config as the source of retry
retryCodesConfig = RetryCodesConfig.create(interfaceConfigProto, new ArrayList<>(interfaceInput.getMethodsToGenerate().keySet()), protoParser);
retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(interfaceConfigProto);
}
ImmutableMap<String, GapicMethodConfig> methodConfigsMap;
List<GapicMethodConfig> methodConfigs;
if (retryCodesConfig != null && retrySettingsDefinition != null) {
methodConfigsMap = createMethodConfigMap(diagCollector, language, transportProtocol, defaultPackageName, methodsToGenerate, messageConfigs, resourceNameConfigs, retryCodesConfig, retrySettingsDefinition.keySet(), protoParser, grpcGapicRetryMapping, interfaceInput.getInterfaceConfigProto().getName());
if (methodConfigsMap == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Error constructing methodConfigMap"));
return null;
}
methodConfigs = ImmutableList.copyOf(methodConfigsMap.values());
} else {
methodConfigsMap = ImmutableMap.of();
methodConfigs = ImmutableList.of();
}
SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto);
ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
if (!CONSTRUCTOR_PARAMS.contains(param)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
}
}
ImmutableSet.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableSet.builder();
if (!protoParser.isProtoAnnotationsEnabled()) {
for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (!(resourceName instanceof SingleResourceNameConfig)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName));
return null;
}
resourcesBuilder.add((SingleResourceNameConfig) resourceName);
}
} else {
addDeprecatedResources(diagCollector, resourcesBuilder, interfaceConfigProto, language);
}
ImmutableSet<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language.toString().toLowerCase())).trim();
if (diagCollector.hasErrors()) {
return null;
} else {
return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigsMap, retryCodesConfig, retrySettingsDefinition, requiredConstructorParams, singleResourceNames, manualDoc);
}
}
Aggregations