Search in sources :

Example 6 with Method

use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.

the class NodeJSSurfaceNamer method returnCallbackDocLines.

private List<String> returnCallbackDocLines(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
    String returnTypeDoc = returnTypeDoc(typeTable, methodConfig);
    Method method = methodConfig.getMethod();
    MethodModel methodModel = methodConfig.getMethodModel();
    String classInfo = getParamTypeName(typeTable, methodModel.getOutputType());
    String callbackType;
    if (isProtobufEmpty(method.getOutputMessage())) {
        callbackType = "function(?Error)";
    } else if (methodConfig.isPageStreaming()) {
        callbackType = String.format("function(?Error, ?Array, ?Object, ?%s)", classInfo);
    } else {
        callbackType = String.format("function(?Error, ?%s)", classInfo);
    }
    ImmutableList.Builder<String> callbackLines = ImmutableList.builder();
    callbackLines.add("@param {" + callbackType + "} [callback]", "  The function which will be called with the result of the API call.");
    if (!isProtobufEmpty(method.getOutputMessage())) {
        callbackLines.add("", "  The second parameter to the callback is " + returnTypeDoc + ".");
        if (methodConfig.isPageStreaming()) {
            callbackLines.add("", "  When autoPaginate: false is specified through options, it contains the result", "  in a single response. If the response indicates the next page exists, the third", "  parameter is set to be used for the next request object. The fourth parameter keeps", "  the raw response object of " + getTypeNameDoc(typeTable, methodModel.getOutputType()) + ".");
        }
    }
    return callbackLines.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.tools.framework.model.Method)

Example 7 with Method

use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.

the class ProtoInterfaceModel method getMethods.

@Override
public List<MethodModel> getMethods() {
    ImmutableList.Builder<MethodModel> methods = ImmutableList.builder();
    for (Method method : protoInterface.getMethods()) {
        methods.add(new ProtoMethodModel(method));
    }
    SymbolTable symbolTable = protoInterface.getModel().getSymbolTable();
    for (Mixin mixin : protoInterface.getConfig().getMixinsList()) {
        Interface mixinInterface = symbolTable.lookupInterface(mixin.getName());
        for (Method method : mixinInterface.getMethods()) {
            methods.add(new ProtoMethodModel(method));
        }
    }
    return methods.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SymbolTable(com.google.api.tools.framework.model.SymbolTable) Method(com.google.api.tools.framework.model.Method) Interface(com.google.api.tools.framework.model.Interface) Mixin(com.google.protobuf.Mixin)

Example 8 with Method

use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.

the class ProtoInterfaceTransformer method getResourceToEntityNameMap.

@Override
public Map<String, String> getResourceToEntityNameMap(InterfaceModel apiInterface) {
    Interface protoInterface = ((ProtoInterfaceModel) apiInterface).getInterface();
    // Using a map with the string representation of the resource path to avoid duplication
    // of equivalent paths.
    // Using a TreeMap in particular so that the ordering is deterministic
    // (useful for testability).
    Map<String, CollectionPattern> specs = new TreeMap<>();
    for (Method method : protoInterface.getReachableMethods()) {
        for (CollectionPattern collectionPattern : CollectionPattern.getCollectionPatternsFromMethod(method)) {
            String resourcePath = collectionPattern.getTemplatizedResourcePath();
            // If there are multiple field segments with the same resource path, the last
            // one will be used, making the output deterministic. Also, the first field path
            // encountered tends to be simply "name" because it is the corresponding create
            // API method for the type.
            specs.put(resourcePath, collectionPattern);
        }
    }
    Set<String> usedNameSet = new HashSet<>();
    ImmutableMap.Builder<String, String> nameMapBuilder = ImmutableMap.builder();
    for (CollectionPattern collectionPattern : specs.values()) {
        String resourceNameString = collectionPattern.getTemplatizedResourcePath();
        String entityNameString = collectionPattern.getUniqueName(usedNameSet);
        usedNameSet.add(entityNameString);
        nameMapBuilder.put(resourceNameString, entityNameString);
    }
    return nameMapBuilder.build();
}
Also used : ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) Interface(com.google.api.tools.framework.model.Interface) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 9 with Method

use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.

the class GapicInterfaceConfig method createMethodConfigMap.

private static ImmutableMap<String, GapicMethodConfig> createMethodConfigMap(DiagCollector diagCollector, String language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ImmutableSet<String> retryCodesConfigNames, ImmutableSet<String> retryParamsConfigNames) {
    ImmutableMap.Builder<String, GapicMethodConfig> methodConfigMapBuilder = ImmutableMap.builder();
    for (MethodConfigProto methodConfigProto : interfaceConfigProto.getMethodsList()) {
        Interface targetInterface = getTargetInterface(apiInterface, methodConfigProto.getRerouteToGrpcInterface());
        Method method = targetInterface.lookupMethod(methodConfigProto.getName());
        if (method == null) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "method not found: %s", methodConfigProto.getName()));
            continue;
        }
        GapicMethodConfig methodConfig = GapicMethodConfig.createMethodConfig(diagCollector, language, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfigNames, retryParamsConfigNames);
        if (methodConfig == null) {
            continue;
        }
        methodConfigMapBuilder.put(methodConfigProto.getName(), methodConfig);
    }
    if (diagCollector.getErrorCount() > 0) {
        return null;
    } else {
        return methodConfigMapBuilder.build();
    }
}
Also used : MethodConfigProto(com.google.api.codegen.MethodConfigProto) Method(com.google.api.tools.framework.model.Method) ImmutableMap(com.google.common.collect.ImmutableMap) Interface(com.google.api.tools.framework.model.Interface)

Aggregations

Method (com.google.api.tools.framework.model.Method)9 ImmutableList (com.google.common.collect.ImmutableList)5 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)3 Interface (com.google.api.tools.framework.model.Interface)3 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodModel (com.google.api.codegen.config.MethodModel)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 HttpRule (com.google.api.HttpRule)1 Service (com.google.api.Service)1 MethodConfigProto (com.google.api.codegen.MethodConfigProto)1 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 HeaderRequestParamView (com.google.api.codegen.viewmodel.HeaderRequestParamView)1 RestInterfaceConfigView (com.google.api.codegen.viewmodel.RestInterfaceConfigView)1 MessageType (com.google.api.tools.framework.model.MessageType)1 SymbolTable (com.google.api.tools.framework.model.SymbolTable)1