Search in sources :

Example 1 with GapicInterfaceConfig

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

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

the class GoGapicSurfaceTransformer method generate.

private StaticLangClientFileView generate(GapicInterfaceContext context) {
    StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
    SurfaceNamer namer = context.getNamer();
    ApiModel model = context.getApiModel();
    ProtoInterfaceModel apiInterface = context.getInterfaceModel();
    GapicProductConfig productConfig = context.getProductConfig();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    view.templateFileName(API_TEMPLATE_FILENAME);
    view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    view.domainLayerLocation(productConfig.getDomainLayerLocation());
    view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
    view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
    view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
    view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
    view.serviceOriginalName(model.getTitle());
    view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
    String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
    String fileName = namer.getServiceFileName(context.getInterfaceConfig());
    view.outputPath(outputPath + File.separator + fileName);
    List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
    view.retryPairDefinitions(retryDef);
    view.callSettings(apiCallableTransformer.generateCallSettings(context));
    List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
    view.apiMethods(apiMethods);
    // If any methods have header request params, "fmt" is needed for `fmt.Sprintf` calls.
    if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
        context.getImportTypeTable().saveNicknameFor("fmt;;;");
    }
    view.iamResources(iamResourceTransformer.generateIamResources(context));
    if (!((GapicInterfaceConfig) productConfig.getInterfaceConfig(apiInterface.getFullName())).getIamResources().isEmpty()) {
        context.getImportTypeTable().saveNicknameFor("cloud.google.com/go/iam;;;");
    }
    // In Go, multiple methods share the same iterator type, one iterator type per resource type.
    // We have to dedupe the iterators.
    Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
    for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
        iterators.put(desc.typeName(), desc);
    }
    view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
    // Same with long running operations.
    Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
    for (StaticLangApiMethodView apiMethod : apiMethods) {
        LongRunningOperationDetailView lro = apiMethod.operationMethod();
        if (lro != null) {
            lros.put(lro.clientReturnTypeName(), lro);
        }
    }
    view.lroDetailViews(new ArrayList<>(lros.values()));
    view.serviceAddress(context.getApiModel().getServiceAddress());
    view.servicePort(model.getServicePort());
    view.stubs(grpcStubTransformer.generateGrpcStubs(context));
    addXApiImports(context, context.getSupportedMethods());
    view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return view.build();
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) TreeMap(java.util.TreeMap) LongRunningOperationDetailView(com.google.api.codegen.viewmodel.LongRunningOperationDetailView) StaticLangClientFileView(com.google.api.codegen.viewmodel.StaticLangClientFileView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PageStreamingDescriptorClassView(com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)

Example 3 with GapicInterfaceConfig

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

the class PhpGapicSurfaceTransformer method addApiImports.

private void addApiImports(GapicInterfaceContext context) {
    ModelTypeTable typeTable = context.getImportTypeTable();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    typeTable.saveNicknameFor("\\Google\\ApiCore\\ApiException");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\Call");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\GapicClientTrait");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\PathTemplate");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\RequestParamsHeaderDescriptor");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\RetrySettings");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\Transport\\TransportInterface");
    typeTable.saveNicknameFor("\\Google\\ApiCore\\ValidationException");
    typeTable.saveNicknameFor("\\Google\\Auth\\CredentialsLoader");
    typeTable.saveNicknameFor("\\Grpc\\Channel");
    typeTable.saveNicknameFor("\\Grpc\\ChannelCredentials");
    if (interfaceConfig.hasLongRunningOperations()) {
        typeTable.saveNicknameFor("\\Google\\ApiCore\\LongRunning\\OperationsClient");
        typeTable.saveNicknameFor("\\Google\\ApiCore\\OperationResponse");
    }
}
Also used : ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig)

Example 4 with GapicInterfaceConfig

use of com.google.api.codegen.config.GapicInterfaceConfig 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)

Aggregations

GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)4 MethodConfig (com.google.api.codegen.config.MethodConfig)2 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 Method (com.google.api.tools.framework.model.Method)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 HttpRule (com.google.api.HttpRule)1 Service (com.google.api.Service)1 ApiModel (com.google.api.codegen.config.ApiModel)1 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)1 LongRunningOperationDetailView (com.google.api.codegen.viewmodel.LongRunningOperationDetailView)1 PageStreamingDescriptorClassView (com.google.api.codegen.viewmodel.PageStreamingDescriptorClassView)1 RestInterfaceConfigView (com.google.api.codegen.viewmodel.RestInterfaceConfigView)1 RetryConfigDefinitionView (com.google.api.codegen.viewmodel.RetryConfigDefinitionView)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1