Search in sources :

Example 41 with MethodConfig

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

the class MockServiceTransformer method createMockGrpcMethodViews.

public List<MockGrpcMethodView> createMockGrpcMethodViews(InterfaceContext context) {
    if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        return ImmutableList.of();
    }
    List<MethodModel> methods = context.getInterfaceMethods();
    ArrayList<MockGrpcMethodView> mocks = new ArrayList<>(methods.size());
    for (MethodModel method : methods) {
        if (context.getMethodConfig(method) == null) {
            continue;
        }
        MethodContext methodContext = context.asRequestMethodContext(method);
        String requestTypeName = method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
        String responseTypeName = method.getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
        MethodConfig methodConfig = methodContext.getMethodConfig();
        mocks.add(MockGrpcMethodView.newBuilder().name(methodContext.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).requestTypeName(requestTypeName).responseTypeName(responseTypeName).grpcStreamingType(methodConfig.getGrpcStreamingType()).streamHandleTypeName(methodContext.getNamer().getStreamingServerName(method)).build());
    }
    return mocks;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) MockGrpcMethodView(com.google.api.codegen.viewmodel.testing.MockGrpcMethodView) ArrayList(java.util.ArrayList)

Example 42 with MethodConfig

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

the class CSharpGapicClientTransformer method generateModifyMethods.

private List<ModifyMethodView> generateModifyMethods(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    List<ModifyMethodView> modifyMethods = new ArrayList<>();
    Set<String> modifyTypeNames = new HashSet<>();
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        MethodContext methodContext = context.asRequestMethodContext(method);
        String inputTypeFullName = methodContext.getMethodModel().getInputFullName();
        if (modifyTypeNames.contains(inputTypeFullName)) {
            continue;
        }
        modifyTypeNames.add(inputTypeFullName);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        ModifyMethodView.Builder builder = ModifyMethodView.builder();
        builder.name(namer.getModifyMethodName(methodContext));
        builder.requestTypeName(method.getAndSaveRequestTypeName(context.getImportTypeTable(), context.getNamer()));
        builder.grpcStreamingType(methodConfig.getGrpcStreamingType());
        modifyMethods.add(builder.build());
    }
    return modifyMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ModifyMethodView(com.google.api.codegen.viewmodel.ModifyMethodView) HashSet(java.util.HashSet)

Example 43 with MethodConfig

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

the class CSharpSurfaceNamer method getReturnDocLines.

@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    MethodConfig methodConfig = methodContext.getMethodConfig();
    if (methodConfig.isPageStreaming()) {
        FieldModel resourceType = methodConfig.getPageStreaming().getResourcesField();
        String resourceTypeName = context.getImportTypeTable().getAndSaveNicknameForElementType(resourceType);
        switch(synchronicity) {
            case Sync:
                return ImmutableList.of("A pageable sequence of <see cref=\"" + resourceTypeName + "\"/> resources.");
            case Async:
                return ImmutableList.of("A pageable asynchronous sequence of <see cref=\"" + resourceTypeName + "\"/> resources.");
        }
    } else if (methodConfig.isGrpcStreaming()) {
        switch(methodConfig.getGrpcStreamingType()) {
            case ServerStreaming:
                return ImmutableList.of("The server stream.");
            case BidiStreaming:
                return ImmutableList.of("The client-server stream.");
            default:
                throw new IllegalStateException("Invalid streaming: " + methodConfig.getGrpcStreamingType());
        }
    } else {
        boolean hasReturn = !methodConfig.getMethodModel().isOutputTypeEmpty();
        switch(synchronicity) {
            case Sync:
                return hasReturn ? ImmutableList.of("The RPC response.") : ImmutableList.of();
            case Async:
                return ImmutableList.of(hasReturn ? "A Task containing the RPC response." : "A Task that completes when the RPC has completed.");
        }
    }
    throw new IllegalStateException("Invalid Synchronicity: " + synchronicity);
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldModel(com.google.api.codegen.config.FieldModel)

Example 44 with MethodConfig

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

the class GoGapicSurfaceTransformer method generateApiMethods.

@VisibleForTesting
List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context, Iterable<MethodModel> methods) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    for (MethodModel method : methods) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext methodContext = context.asRequestMethodContext(method);
        if (method.getRequestStreaming() || method.getResponseStreaming()) {
            apiMethods.add(apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(methodContext));
        } else if (methodConfig.isPageStreaming()) {
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(methodContext));
        } else if (methodConfig.isLongRunningOperation()) {
            apiMethods.add(apiMethodTransformer.generateOperationRequestObjectMethod(methodContext));
        } else {
            apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(methodContext));
        }
    }
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.transformer.MethodContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 45 with MethodConfig

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

the class GoGapicSurfaceTransformer method generateRetryConfigDefinitions.

@VisibleForTesting
List<RetryConfigDefinitionView> generateRetryConfigDefinitions(InterfaceContext context, List<MethodModel> methods) {
    Set<RetryConfigDefinitionView.Name> retryNames = new HashSet<>();
    for (MethodModel method : methods) {
        MethodConfig conf = context.getMethodConfig(method);
        retryNames.add(RetryConfigDefinitionView.Name.create(conf.getRetrySettingsConfigName(), conf.getRetryCodesConfigName()));
    }
    TreeMap<RetryConfigDefinitionView.Name, RetryConfigDefinitionView> retryDef = new TreeMap<>();
    Map<String, ImmutableSet<String>> retryCodesDef = context.getInterfaceConfig().getRetryCodesDefinition();
    Map<String, RetrySettings> retryParamsDef = context.getInterfaceConfig().getRetrySettingsDefinition();
    for (RetryConfigDefinitionView.Name name : retryNames) {
        ImmutableSet<String> codes = retryCodesDef.get(name.retryCodesConfigName());
        if (codes.isEmpty()) {
            continue;
        }
        List<String> retryCodeNames = new ArrayList<>();
        for (String code : codes) {
            retryCodeNames.add(context.getNamer().getStatusCodeName(code));
        }
        retryDef.put(name, RetryConfigDefinitionView.newBuilder().name(name).retryCodes(retryCodeNames).params(retryParamsDef.get(name.retrySettingsConfigName())).build());
    }
    if (!retryDef.isEmpty()) {
        context.getImportTypeTable().saveNicknameFor("time;;;");
        context.getImportTypeTable().saveNicknameFor("google.golang.org/grpc/codes;;;");
    }
    return new ArrayList<>(retryDef.values());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RetryConfigDefinitionView(com.google.api.codegen.viewmodel.RetryConfigDefinitionView) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) MethodConfig(com.google.api.codegen.config.MethodConfig) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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