Search in sources :

Example 1 with GapicMethodConfig

use of com.google.api.codegen.config.GapicMethodConfig 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 2 with GapicMethodConfig

use of com.google.api.codegen.config.GapicMethodConfig 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 3 with GapicMethodConfig

use of com.google.api.codegen.config.GapicMethodConfig 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 4 with GapicMethodConfig

use of com.google.api.codegen.config.GapicMethodConfig in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method addMethodImports.

private void addMethodImports(GapicMethodContext context) {
    ModelTypeTable typeTable = context.getTypeTable();
    GapicMethodConfig methodConfig = context.getMethodConfig();
    if (methodConfig.isLongRunningOperation()) {
        typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType());
        typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType());
    }
    typeTable.getAndSaveNicknameFor(context.getMethod().getInputType());
    addFieldsImports(typeTable, methodConfig.getRequiredFields());
    addFieldsImports(typeTable, methodConfig.getOptionalFields());
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable)

Example 5 with GapicMethodConfig

use of com.google.api.codegen.config.GapicMethodConfig in project toolkit by googleapis.

the class PythonSurfaceNamer method getReturnDocLines.

@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    TypeRef outputType = ((GapicMethodConfig) methodConfig).getMethod().getOutputType();
    if (ServiceMessages.s_isEmptyType(outputType)) {
        return ImmutableList.<String>of();
    }
    String returnTypeName = methodConfig.isLongRunningOperation() ? "google.gax._OperationFuture" : getModelTypeFormatter().getFullNameFor(outputType);
    String classInfo = PythonDocstringUtil.napoleonType(returnTypeName, getVersionedDirectoryNamespace());
    if (((GapicMethodConfig) methodConfig).getMethod().getResponseStreaming()) {
        return ImmutableList.of("Iterable[" + classInfo + "].");
    }
    if (methodConfig.isPageStreaming()) {
        FieldModel fieldModel = methodConfig.getPageStreaming().getResourcesField();
        return ImmutableList.of("A :class:`~google.gax.PageIterator` instance. By default, this", "is an iterable of " + annotateWithClass(getResponseTypeNameForElementType(fieldModel.getType())) + " instances.", "This object can also be configured to iterate over the pages", "of the response through the `options` parameter.");
    }
    return ImmutableList.of(String.format("A %s instance.", annotateWithClass(classInfo)));
}
Also used : GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) MethodConfig(com.google.api.codegen.config.MethodConfig) TypeRef(com.google.api.tools.framework.model.TypeRef) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)7 MethodConfig (com.google.api.codegen.config.MethodConfig)3 Method (com.google.api.tools.framework.model.Method)3 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)2 ImmutableList (com.google.common.collect.ImmutableList)2 FieldModel (com.google.api.codegen.config.FieldModel)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 ProtoMethodModel (com.google.api.codegen.config.ProtoMethodModel)1 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)1 HeaderRequestParamView (com.google.api.codegen.viewmodel.HeaderRequestParamView)1 Interface (com.google.api.tools.framework.model.Interface)1 MessageType (com.google.api.tools.framework.model.MessageType)1 TypeRef (com.google.api.tools.framework.model.TypeRef)1 ArrayList (java.util.ArrayList)1