use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class GapicInterfaceContext method createGrpcRerouteMap.
private static Map<Interface, Interface> createGrpcRerouteMap(Model model, GapicProductConfig productConfig) {
HashMap<Interface, Interface> grpcRerouteMap = new HashMap<>();
for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
if (!apiInterface.isReachable()) {
continue;
}
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
String reroute = methodConfig.getRerouteToGrpcInterface();
if (!Strings.isNullOrEmpty(reroute)) {
Interface targetInterface = model.getSymbolTable().lookupInterface(reroute);
grpcRerouteMap.put(targetInterface, apiInterface);
}
}
}
return grpcRerouteMap;
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class GapicInterfaceContext method getMethodConfig.
/**
* Returns the MethodConfig object of the given gRPC method.
*
* <p>If the method is a gRPC re-route method, returns the MethodConfig of the original method.
*/
public GapicMethodConfig getMethodConfig(MethodModel method) {
Interface originalInterface = getInterface();
if (getGrpcRerouteMap().containsKey(originalInterface)) {
originalInterface = getGrpcRerouteMap().get(originalInterface);
}
InterfaceConfig originalInterfaceConfig = getProductConfig().getInterfaceConfig(originalInterface);
if (originalInterfaceConfig != null) {
return (GapicMethodConfig) originalInterfaceConfig.getMethodConfig(method);
} else {
throw new IllegalArgumentException("Interface config does not exist for method: " + method.getSimpleName());
}
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class ProtoConfigMerger method getPackageName.
private String getPackageName(Model model, ConfigHelper helper) {
if (model.getServiceConfig().getApisCount() > 0) {
Api api = model.getServiceConfig().getApis(0);
Interface apiInterface = model.getSymbolTable().lookupInterface(api.getName());
if (apiInterface != null) {
return apiInterface.getFile().getFullName();
}
}
helper.error(model.getLocation(), "No interface found");
return null;
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class GapicProductConfig method createInterfaceConfigMap.
private static ImmutableMap<String, InterfaceConfig> createInterfaceConfigMap(DiagCollector diagCollector, ConfigProto configProto, LanguageSettingsProto languageSettings, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, SymbolTable symbolTable) {
ImmutableMap.Builder<String, InterfaceConfig> interfaceConfigMap = ImmutableMap.builder();
for (InterfaceConfigProto interfaceConfigProto : configProto.getInterfacesList()) {
Interface apiInterface = symbolTable.lookupInterface(interfaceConfigProto.getName());
if (apiInterface == null || !apiInterface.isReachable()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "interface not found: %s", interfaceConfigProto.getName()));
continue;
}
String interfaceNameOverride = languageSettings.getInterfaceNames().get(interfaceConfigProto.getName());
GapicInterfaceConfig interfaceConfig = GapicInterfaceConfig.createInterfaceConfig(diagCollector, configProto.getLanguage(), interfaceConfigProto, apiInterface, interfaceNameOverride, messageConfigs, resourceNameConfigs);
if (interfaceConfig == null) {
continue;
}
interfaceConfigMap.put(interfaceConfigProto.getName(), interfaceConfig);
}
if (diagCollector.getErrorCount() > 0) {
return null;
} else {
return interfaceConfigMap.build();
}
}
use of com.google.api.tools.framework.model.Interface in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method versionedInitRequireViews.
private List<VersionIndexRequireView> versionedInitRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
for (Interface apiInterface : apiInterfaces) {
views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
}
return views.build();
}
Aggregations