Search in sources :

Example 6 with MethodContext

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

use of com.google.api.codegen.transformer.MethodContext 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 8 with MethodContext

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

the class GoGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    MethodContext methodContext = context.asRequestMethodContext(method);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(namer.getSmokeTestClassName(context.getInterfaceConfig()));
    testClass.outputPath(context.getProductConfig().getPackageName() + File.separator + method.getSimpleName() + "_smoke_test.go");
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    // The shared code above add imports both for input and output.
    // Since we use short decls, we don't need to import anything for output.
    context.getImportTypeTable().getImports().clear();
    method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 9 with MethodContext

use of com.google.api.codegen.transformer.MethodContext 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 10 with MethodContext

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

the class JavaSurfaceTestTransformer method createTestCaseViews.

private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
    ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
    SymbolTable testNameTable = new SymbolTable();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        if (methodConfig.isGrpcStreaming()) {
            if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
                // Issue: https://github.com/googleapis/toolkit/issues/946
                continue;
            }
            addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
            MethodContext methodContext = context.asRequestMethodContext(method);
            InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
            testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
        } else if (methodConfig.isFlattening()) {
            ClientMethodType clientMethodType;
            if (methodConfig.isPageStreaming()) {
                clientMethodType = ClientMethodType.PagedFlattenedMethod;
            } else if (methodConfig.isLongRunningOperation()) {
                clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
            } else {
                clientMethodType = ClientMethodType.FlattenedMethod;
            }
            for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
                testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
            }
        } else {
            // TODO: Add support of non-flattening method
            // Github issue: https://github.com/googleapis/toolkit/issues/393
            System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
        }
    }
    return testCaseViews;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) TestCaseView(com.google.api.codegen.viewmodel.testing.TestCaseView) ArrayList(java.util.ArrayList) SymbolTable(com.google.api.codegen.util.SymbolTable) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext)

Aggregations

MethodContext (com.google.api.codegen.transformer.MethodContext)10 MethodConfig (com.google.api.codegen.config.MethodConfig)8 MethodModel (com.google.api.codegen.config.MethodModel)8 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)6 ArrayList (java.util.ArrayList)6 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)4 FieldConfig (com.google.api.codegen.config.FieldConfig)3 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)2 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)2 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)2 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)2 ImmutableList (com.google.common.collect.ImmutableList)2 ApiModel (com.google.api.codegen.config.ApiModel)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)1 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)1 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)1