Search in sources :

Example 6 with ParamWithSimpleDoc

use of com.google.api.codegen.transformer.ParamWithSimpleDoc in project toolkit by googleapis.

the class CSharpApiMethodTransformer method generateApiMethods.

@Override
public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext interfaceContext) {
    Preconditions.checkArgument(interfaceContext instanceof GapicInterfaceContext, "Only applicable for protobuf-based API in CSharp.");
    GapicInterfaceContext context = (GapicInterfaceContext) interfaceContext;
    List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    // gRPC streaming methods.
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedStreamingBidi, CallingForm.FlattenedStreamingServer));
                    apiMethods.add(generateGrpcStreamingFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), null));
                }
            }
            requestMethodContext = requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestStreamingBidi, CallingForm.RequestStreamingServer));
            apiMethods.add(generateGrpcStreamingRequestObjectMethod(requestMethodContext, null));
        } else if (requestMethodContext.isLongRunningMethodContext()) {
            // LRO methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateFlattenedLroMethods(methodContext));
                }
            }
            apiMethods.add(generateAsyncOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestAsyncPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), true, null));
            apiMethods.add(generateOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), null));
        } else if (methodConfig.isPageStreaming()) {
            // Paged streaming methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generatePageStreamingFlattenedMethods(methodContext, pagedMethodAdditionalParams));
                }
            }
            apiMethods.add(generatePagedRequestObjectAsyncMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestAsyncPaged, CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
            apiMethods.add(generatePagedRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged, CallingForm.RequestPagedAll, CallingForm.RequestPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
        } else {
            // Unary methods.
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
                    apiMethods.addAll(generateNormalFlattenedMethods(methodContext));
                }
            }
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod, null));
            apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod, null));
            apiMethods.add(generateRequestObjectMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), csharpCommonTransformer.callSettingsParam(), null));
        }
    }
    return apiMethods;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) MethodContext(com.google.api.codegen.config.MethodContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Aggregations

ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)4 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ArrayList (java.util.ArrayList)3 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)2 MethodModel (com.google.api.codegen.config.MethodModel)2 ImmutableList (com.google.common.collect.ImmutableList)2 FieldConfig (com.google.api.codegen.config.FieldConfig)1 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)1 MethodContext (com.google.api.codegen.config.MethodContext)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 InitCodeTransformer (com.google.api.codegen.transformer.InitCodeTransformer)1 MethodContext (com.google.api.codegen.transformer.MethodContext)1 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)1