Search in sources :

Example 6 with MethodConfig

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

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

the class LongRunningTransformer method generateDetailView.

LongRunningOperationDetailView generateDetailView(MethodContext context) {
    MethodConfig methodConfig = context.getMethodConfig();
    LongRunningConfig lroConfig = methodConfig.getLongRunningConfig();
    SurfaceNamer namer = context.getNamer();
    String clientReturnTypeName = namer.getAndSaveOperationResponseTypeName(context.getMethodModel(), context.getTypeTable(), methodConfig);
    String operationPayloadTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getReturnType());
    String metadataTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getMetadataType());
    return LongRunningOperationDetailView.newBuilder().methodName(namer.getApiMethodName(context.getMethodModel(), VisibilityConfig.PUBLIC)).constructorName(namer.getTypeConstructor(clientReturnTypeName)).clientReturnTypeName(clientReturnTypeName).operationPayloadTypeName(operationPayloadTypeName).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(metadataTypeName).implementsDelete(lroConfig.implementsDelete()).implementsCancel(lroConfig.implementsCancel()).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) LongRunningConfig(com.google.api.codegen.config.LongRunningConfig)

Example 8 with MethodConfig

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

the class MockServiceTransformer method getGrpcInterfacesForService.

public Map<String, InterfaceModel> getGrpcInterfacesForService(ApiModel model, GapicProductConfig productConfig, InterfaceModel apiInterface) {
    if (!productConfig.getTransportProtocol().equals(TransportProtocol.GRPC)) {
        return ImmutableMap.of();
    }
    Map<String, InterfaceModel> interfaces = new LinkedHashMap<>();
    interfaces.put(apiInterface.getFullName(), apiInterface);
    InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
    for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
        String reroute = methodConfig.getRerouteToGrpcInterface();
        if (!Strings.isNullOrEmpty(reroute)) {
            InterfaceModel targetInterface = model.getInterface(reroute);
            interfaces.put(reroute, targetInterface);
        }
    }
    return interfaces;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with MethodConfig

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

the class PageStreamingTransformer method generateDescriptor.

public PageStreamingDescriptorView generateDescriptor(InterfaceContext context, MethodModel method) {
    MethodConfig methodConfig = context.getMethodConfig(method);
    PageStreamingConfig pageStreaming = methodConfig.getPageStreaming();
    PageStreamingDescriptorView.Builder descriptor = PageStreamingDescriptorView.newBuilder();
    descriptor.varName(context.getNamer().getPageStreamingDescriptorName(method));
    descriptor.requestTokenFieldName(context.getNamer().getRequestTokenFieldName(pageStreaming));
    descriptor.requestTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getRequestTokenField()));
    descriptor.requestTokenSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getRequestTokenField()));
    if (pageStreaming.hasPageSizeField()) {
        descriptor.requestPageSizeFieldName(context.getNamer().getPageSizeFieldName(pageStreaming));
        descriptor.requestPageSizeGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getPageSizeField()));
        descriptor.requestPageSizeSetMethodName(context.getNamer().getFieldSetFunctionName(pageStreaming.getPageSizeField()));
    }
    descriptor.responseTokenFieldName(context.getNamer().getResponseTokenFieldName(pageStreaming));
    descriptor.responseTokenGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResponseTokenField()));
    descriptor.resourcesFieldName(context.getNamer().getResourcesFieldName(pageStreaming));
    descriptor.resourcesGetMethodName(context.getNamer().getFieldGetFunctionName(pageStreaming.getResourcesField()));
    descriptor.methodName(context.getNamer().getMethodKey(method));
    descriptor.transportMethodName(context.getNamer().getGrpcMethodName(method));
    return descriptor.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) PageStreamingDescriptorView(com.google.api.codegen.viewmodel.PageStreamingDescriptorView)

Example 10 with MethodConfig

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

the class PathTemplateTransformer method getSingleResourceNameConfigsUsedByInterface.

private List<SingleResourceNameConfig> getSingleResourceNameConfigsUsedByInterface(InterfaceContext context) {
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    Set<String> foundSet = new HashSet<>();
    ImmutableList.Builder<SingleResourceNameConfig> resourceNameConfigsBuilder = ImmutableList.builder();
    for (SingleResourceNameConfig config : interfaceConfig.getSingleResourceNameConfigs()) {
        resourceNameConfigsBuilder.add(config);
        foundSet.add(config.getEntityId());
    }
    for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
        MethodContext methodContext = context.asRequestMethodContext(methodConfig.getMethodModel());
        for (String fieldNamePattern : methodConfig.getFieldNamePatterns().values()) {
            SingleResourceNameConfig resourceNameConfig = methodContext.getSingleResourceNameConfig(fieldNamePattern);
            if (resourceNameConfig != null && !foundSet.contains(resourceNameConfig.getEntityId())) {
                resourceNameConfigsBuilder.add(resourceNameConfig);
                foundSet.add(resourceNameConfig.getEntityId());
            }
        }
    }
    return resourceNameConfigsBuilder.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImmutableList(com.google.common.collect.ImmutableList) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig) HashSet(java.util.HashSet)

Aggregations

MethodConfig (com.google.api.codegen.config.MethodConfig)51 MethodModel (com.google.api.codegen.config.MethodModel)29 ArrayList (java.util.ArrayList)20 ImmutableList (com.google.common.collect.ImmutableList)14 FieldModel (com.google.api.codegen.config.FieldModel)13 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)9 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)8 MethodContext (com.google.api.codegen.transformer.MethodContext)8 FieldConfig (com.google.api.codegen.config.FieldConfig)7 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)6 SimpleParamDocView (com.google.api.codegen.viewmodel.SimpleParamDocView)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)5 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)3 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)3 SymbolTable (com.google.api.codegen.util.SymbolTable)3