Search in sources :

Example 1 with Interface

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;
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) HashMap(java.util.HashMap) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface)

Example 2 with Interface

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());
    }
}
Also used : GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) Interface(com.google.api.tools.framework.model.Interface)

Example 3 with Interface

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;
}
Also used : Api(com.google.protobuf.Api) Interface(com.google.api.tools.framework.model.Interface)

Example 4 with Interface

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();
    }
}
Also used : InterfaceConfigProto(com.google.api.codegen.InterfaceConfigProto) ImmutableMap(com.google.common.collect.ImmutableMap) Interface(com.google.api.tools.framework.model.Interface)

Example 5 with Interface

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Aggregations

Interface (com.google.api.tools.framework.model.Interface)17 InterfaceView (com.google.api.codegen.InterfaceView)7 ImmutableList (com.google.common.collect.ImmutableList)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 Method (com.google.api.tools.framework.model.Method)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 TreeSet (java.util.TreeSet)2 ConfigProto (com.google.api.codegen.ConfigProto)1 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)1 MethodConfigProto (com.google.api.codegen.MethodConfigProto)1 ClientConfigGapicContext (com.google.api.codegen.clientconfig.ClientConfigGapicContext)1 ClientConfigSnippetSetRunner (com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner)1 PhpClientConfigGapicContext (com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 NodeJSCodePathMapper (com.google.api.codegen.nodejs.NodeJSCodePathMapper)1 PhpGapicCodePathMapper (com.google.api.codegen.php.PhpGapicCodePathMapper)1