use of com.google.api.codegen.CollectionConfigProto in project toolkit by googleapis.
the class DiscoGapicInterfaceConfig method createInterfaceConfig.
static DiscoGapicInterfaceConfig createInterfaceConfig(DiscoApiModel model, String language, InterfaceConfigProto interfaceConfigProto, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(model.getDiagCollector(), interfaceConfigProto);
ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(model.getDiagCollector(), interfaceConfigProto);
List<DiscoGapicMethodConfig> methodConfigs = null;
ImmutableMap<String, DiscoGapicMethodConfig> methodConfigMap = null;
if (retryCodesDefinition != null && retrySettingsDefinition != null) {
methodConfigMap = createMethodConfigMap(model, language, interfaceConfigProto, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
methodConfigs = GapicInterfaceConfig.createMethodConfigs(methodConfigMap, interfaceConfigProto);
}
// TODO(andrealin) Make non-null smokeTestConfig.
SmokeTestConfig smokeTestConfig = null;
// TODO(andrealin) IAM permissions configs.
ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
if (!CONSTRUCTOR_PARAMS.contains(param)) {
model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
}
}
ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) {
model.getDiagCollector().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);
}
ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
ImmutableMap.Builder<MethodConfig, SingleResourceNameConfig> methodToSingleResourceNameMap = ImmutableMap.builder();
if (methodConfigs != null) {
for (MethodConfig methodConfig : methodConfigs) {
Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
String canonicalMethodPath = DiscoGapicParser.getCanonicalPath(method);
for (SingleResourceNameConfig nameConfig : singleResourceNames) {
if (nameConfig.getNamePattern().equals(canonicalMethodPath)) {
methodToSingleResourceNameMap.put(methodConfig, nameConfig);
}
}
}
}
String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
String interfaceName = interfaceNameOverride != null ? interfaceNameOverride : DiscoGapicParser.getInterfaceName(interfaceConfigProto.getName()).toUpperCamel();
if (model.getDiagCollector().hasErrors()) {
return null;
} else {
return new AutoValue_DiscoGapicInterfaceConfig(methodConfigs, retryCodesDefinition, retrySettingsDefinition, requiredConstructorParams, manualDoc, interfaceNameOverride, new DiscoInterfaceModel(interfaceName, model), smokeTestConfig, methodToSingleResourceNameMap.build(), methodConfigMap, singleResourceNames);
}
}
use of com.google.api.codegen.CollectionConfigProto 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, String language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(diagCollector, interfaceConfigProto);
ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(diagCollector, interfaceConfigProto);
List<GapicMethodConfig> methodConfigs = null;
ImmutableMap<String, GapicMethodConfig> methodConfigMap = null;
if (retryCodesDefinition != null && retrySettingsDefinition != null) {
methodConfigMap = createMethodConfigMap(diagCollector, language, interfaceConfigProto, apiInterface, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
methodConfigs = createMethodConfigs(methodConfigMap, interfaceConfigProto);
}
SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto);
ImmutableList<FieldModel> iamResources = createIamResources(apiInterface.getModel(), interfaceConfigProto.getExperimentalFeatures().getIamResourcesList());
ImmutableList<String> requiredConstructorParams = ImmutableList.<String>copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
if (!CONSTRUCTOR_PARAMS.contains(param)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
}
}
ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
String entityName = collectionConfigProto.getEntityName();
ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
if (resourceName == null || !(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);
}
ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
if (diagCollector.hasErrors()) {
return null;
} else {
return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigMap, retryCodesDefinition, retrySettingsDefinition, iamResources, requiredConstructorParams, singleResourceNames, manualDoc);
}
}
Aggregations