Search in sources :

Example 1 with Method

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

the class GapicContext method getSupportedMethodsV2.

/**
 * Returns a list of RPC methods supported by the context, taking into account GRPC interface
 * rerouting. TODO replace getSupportedMethods with this when all languages are migrated.
 */
public List<Method> getSupportedMethodsV2(Interface apiInterface) {
    GapicInterfaceConfig interfaceConfig = getApiConfig().getInterfaceConfig(apiInterface);
    if (interfaceConfig == null) {
        throw new IllegalStateException("Service not configured in GAPIC config: " + apiInterface.getFullName());
    }
    List<Method> methods = new ArrayList<>(interfaceConfig.getMethodConfigs().size());
    for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
        Method method = ((GapicMethodConfig) methodConfig).getMethod();
        if (isSupported(method)) {
            methods.add(method);
        }
    }
    return methods;
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ArrayList(java.util.ArrayList) Method(com.google.api.tools.framework.model.Method)

Example 2 with Method

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

the class NodeJSSurfaceNamer method getReturnDocLines.

/**
 * Return JSDoc callback comment and return type comment for the given method.
 */
@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    GapicMethodConfig methodConfig = (GapicMethodConfig) methodContext.getMethodConfig();
    Method method = methodConfig.getMethod();
    if (method.getRequestStreaming() && method.getResponseStreaming()) {
        return bidiStreamingReturnDocLines(method);
    } else if (method.getResponseStreaming()) {
        return responseStreamingReturnDocLines(method);
    }
    List<String> callbackLines = returnCallbackDocLines(context.getImportTypeTable(), methodConfig);
    List<String> returnObjectLines = returnObjectDocLines(context.getImportTypeTable(), methodConfig);
    return ImmutableList.<String>builder().addAll(callbackLines).addAll(returnObjectLines).build();
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) Method(com.google.api.tools.framework.model.Method)

Example 3 with Method

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

the class NodeJSSurfaceNamer method returnObjectDocLines.

private List<String> returnObjectDocLines(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
    String returnTypeDoc = returnTypeDoc(typeTable, methodConfig);
    Method method = methodConfig.getMethod();
    ImmutableList.Builder<String> returnMessageLines = ImmutableList.builder();
    if (method.getRequestStreaming()) {
        returnMessageLines.add("@returns {Stream} - A writable stream which accepts objects representing", "  " + commentReformatter.getLinkedElementName(method.getInputType().getMessageType()) + " for write() method.");
    } else {
        if (isProtobufEmpty(method.getOutputMessage())) {
            returnMessageLines.add("@returns {Promise} - The promise which resolves when API call finishes.");
        } else {
            returnMessageLines.add("@returns {Promise} - The promise which resolves to an array.", "  The first element of the array is " + returnTypeDoc + ".");
            if (methodConfig.isPageStreaming()) {
                returnMessageLines.add("", "  When autoPaginate: false is specified through options, the array has three " + "elements.", "  The first element is " + returnTypeDoc + " in a single response.", "  The second element is the next request object if the response", "  indicates the next page exists, or null. The third element is ", "  " + getTypeNameDoc(typeTable, methodConfig.getMethodModel().getOutputType()) + ".", "");
            }
        }
        returnMessageLines.add("  The promise has a method named \"cancel\" which cancels the ongoing API call.");
    }
    return returnMessageLines.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.tools.framework.model.Method)

Example 4 with Method

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

the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.

private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
    List<RestInterfaceConfigView> configViews = new ArrayList<>();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    SurfaceNamer namer = context.getNamer();
    Map<String, List<HttpRule>> interfaces = new TreeMap<>();
    Service serviceConfig = serviceModel.getServiceConfig();
    for (MethodModel methodModel : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        Method method = methodContext.getMethod();
        // REST does not support streaming methods
        if (methodConfig.isGrpcStreaming()) {
            continue;
        }
        String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
        HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
        String selector = httpRule.getSelector();
        String interfaceName = selector.substring(0, selector.lastIndexOf("."));
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
        configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
    }
    return configViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 5 with Method

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

the class HeaderRequestParamTransformer method generateHeaderRequestParams.

public List<HeaderRequestParamView> generateHeaderRequestParams(MethodContext context) {
    if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        return ImmutableList.of();
    }
    GapicMethodConfig methodConfig = (GapicMethodConfig) context.getMethodConfig();
    Method method = methodConfig.getMethod();
    SurfaceNamer namer = context.getNamer();
    if (method.getInputType() == null || !method.getInputType().isMessage()) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<HeaderRequestParamView> headerRequestParams = ImmutableList.builder();
    MessageType inputMessageType = method.getInputType().getMessageType();
    for (String headerRequestParam : methodConfig.getHeaderRequestParams()) {
        headerRequestParams.add(generateHeaderRequestParam(headerRequestParam, inputMessageType, namer));
    }
    return headerRequestParams.build();
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.tools.framework.model.Method) HeaderRequestParamView(com.google.api.codegen.viewmodel.HeaderRequestParamView) MessageType(com.google.api.tools.framework.model.MessageType)

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