Search in sources :

Example 1 with InitCodeOutputType

use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.

the class DynamicLangApiMethodTransformer method generateMethod.

public OptionalArrayMethodView generateMethod(GapicMethodContext context, boolean packageHasMultipleServices) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    OptionalArrayMethodView.Builder apiMethod = OptionalArrayMethodView.newBuilder();
    if (context.getMethodConfig().isPageStreaming()) {
        apiMethod.type(ClientMethodType.PagedOptionalArrayMethod);
        apiMethod.pageStreamingView(pageStreamingTransformer.generateDescriptor(context.getSurfaceInterfaceContext(), method));
    } else {
        apiMethod.type(ClientMethodType.OptionalArrayMethod);
    }
    apiMethod.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.fullyQualifiedApiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.topLevelAliasedApiClassName(namer.getTopLevelAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.versionAliasedApiClassName(namer.getVersionAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.apiVariableName(namer.getApiWrapperVariableName(context.getInterfaceConfig()));
    apiMethod.apiModuleName(namer.getApiWrapperModuleName());
    apiMethod.localPackageName(namer.getLocalPackageName());
    InitCodeOutputType initCodeOutputType = context.getMethodModel().getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), initCodeOutputType));
    apiMethod.initCode(initCode);
    apiMethod.doc(generateMethodDoc(context));
    apiMethod.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiMethod.requestVariableName(namer.getRequestVariableName(method));
    apiMethod.requestTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getInputType()));
    apiMethod.responseTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getOutputType()));
    apiMethod.hasReturnValue(!ServiceMessages.s_isEmptyType(context.getMethod().getOutputType()));
    apiMethod.key(namer.getMethodKey(method));
    apiMethod.grpcMethodName(namer.getGrpcMethodName(method));
    apiMethod.rerouteToGrpcInterface(context.getMethodConfig().getRerouteToGrpcInterface());
    apiMethod.stubName(namer.getStubName(context.getTargetInterface()));
    apiMethod.methodParams(apiMethodParamTransformer.generateMethodParams(context));
    Iterable<FieldConfig> filteredFieldConfigs = removePageTokenFieldConfig(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> requiredParams = generateRequestObjectParams(context, context.getMethodConfig().getRequiredFieldConfigs());
    List<RequestObjectParamView> optionalParams = generateRequestObjectParams(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> optionalParamsNoPageToken = generateRequestObjectParams(context, filteredFieldConfigs);
    apiMethod.requiredRequestObjectParams(requiredParams);
    apiMethod.optionalRequestObjectParams(optionalParams);
    apiMethod.optionalRequestObjectParamsNoPageToken(optionalParamsNoPageToken);
    apiMethod.hasRequestParameters(!requiredParams.isEmpty() || !optionalParamsNoPageToken.isEmpty());
    apiMethod.hasRequiredParameters(!requiredParams.isEmpty());
    GrpcStreamingType grpcStreamingType = context.getMethodConfig().getGrpcStreamingType();
    apiMethod.grpcStreamingType(grpcStreamingType);
    apiMethod.isSingularRequestMethod(grpcStreamingType.equals(GrpcStreamingType.NonStreaming) || grpcStreamingType.equals(GrpcStreamingType.ServerStreaming));
    apiMethod.packageName(namer.getPackageName());
    apiMethod.packageHasMultipleServices(packageHasMultipleServices);
    apiMethod.packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig()));
    apiMethod.apiVersion(namer.getApiWrapperModuleVersion());
    apiMethod.longRunningView(context.getMethodConfig().isLongRunningOperation() ? lroTransformer.generateDetailView(context) : null);
    apiMethod.oneofParams(context.getMethodConfig().getOneofNames(namer));
    apiMethod.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    return apiMethod.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 2 with InitCodeOutputType

use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.

the class PythonGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ImmutableList.Builder<TestCaseView> testCaseViews = ImmutableList.builder();
    // certain string until all of the types have been disambiguated.
    for (int i = 0; i < 2; ++i) {
        testCaseViews = ImmutableList.builder();
        SymbolTable testNameTable = new SymbolTable();
        for (MethodModel method : context.getSupportedMethods()) {
            GapicMethodContext methodContext = context.asRequestMethodContext(method);
            ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
            if (methodContext.getMethodConfig().isLongRunningOperation()) {
                clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
            } else if (methodContext.getMethodConfig().isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
            }
            Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
            InitCodeOutputType initCodeOutputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
            InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
        }
    }
    return testCaseViews.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ImmutableList(com.google.common.collect.ImmutableList) FieldConfig(com.google.api.codegen.config.FieldConfig) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 3 with InitCodeOutputType

use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createUnitTestCaseInitCodeContext.

private InitCodeContext createUnitTestCaseInitCodeContext(GapicInterfaceContext context, MethodModel method) {
    MethodContext requestMethodContext = context.asRequestMethodContext(method);
    MethodContext dynamicMethodContext = context.asDynamicMethodContext(method);
    MethodConfig methodConfig = requestMethodContext.getMethodConfig();
    Iterable<FieldConfig> fieldConfigs = methodConfig.getRequiredFieldConfigs();
    InitCodeOutputType outputType = method.getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    return InitCodeContext.newBuilder().initObjectType(method.getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodConfig.getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(dynamicMethodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(outputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Example 4 with InitCodeOutputType

use of com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType in project toolkit by googleapis.

the class PhpGapicSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
            // Issue: https://github.com/googleapis/toolkit/issues/946
            continue;
        }
        InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
        if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
            initCodeOutputType = InitCodeOutputType.SingleObject;
        }
        ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
        if (methodContext.getMethodConfig().isLongRunningOperation()) {
            clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
        } else if (methodContext.getMethodConfig().isPageStreaming()) {
            clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
        }
        Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
        InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
        testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
    }
    return testCaseViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)4 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)4 MethodModel (com.google.api.codegen.config.MethodModel)3 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)3 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)2 SymbolTable (com.google.api.codegen.util.SymbolTable)2 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)2 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)2 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodContext (com.google.api.codegen.transformer.MethodContext)1 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)1 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)1 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1