Search in sources :

Example 6 with FlatteningConfig

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

the class JavaSurfaceTestTransformer method createSmokeTestClassViewBuilder.

/**
 * Package-private
 *
 * <p>A helper method that creates a partially initialized builder that can be customized and
 * build the smoke test class view later.
 */
SmokeTestClassView.Builder createSmokeTestClassViewBuilder(InterfaceContext context) {
    addSmokeTestImports(context);
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    SurfaceNamer namer = context.getNamer();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    // Imports must be done as the last step to catch all imports.
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 7 with FlatteningConfig

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

the class JavaSurfaceTransformer method generateApiMethods.

private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    for (MethodModel method : context.getSupportedMethods()) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isPageStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
        } else if (methodConfig.isGrpcStreaming()) {
            ImportTypeTable typeTable = context.getImportTypeTable();
            switch(methodConfig.getGrpcStreamingType()) {
                case BidiStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
                    break;
                case ClientStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
                    break;
                case ServerStreaming:
                    typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
                    break;
                default:
                    throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
            }
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else if (methodConfig.isLongRunningOperation()) {
            context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        } else {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
                    if (hasAnyResourceNameParameter(flatteningGroup)) {
                        apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
                    }
                }
            }
            apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
            apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
        }
    }
    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) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 8 with FlatteningConfig

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

the class NodeJSGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context, boolean packageHasMultipleServices) {
    SurfaceNamer namer = context.getNamer();
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext, packageHasMultipleServices);
    testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.outputPath(namer.getSourceFilePath(SMOKE_TEST_OUTPUT_BASE_PATH, name));
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethodView);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
    testClass.fileHeader(fileHeader);
    return testClass.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView)

Example 9 with FlatteningConfig

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

the class NodeJSPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// Note: This is based on sample gen method calls. In the future, the example
// methods may be configured separately.
private List<ApiMethodView> generateExampleMethods(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ApiMethodView> exampleMethods = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
            FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
            GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
            exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
        }
    }
    return exampleMethods.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 10 with FlatteningConfig

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

the class PhpGapicSurfaceTestTransformer method createSmokeTestClassViewBuilder.

private SmokeTestClassView.Builder createSmokeTestClassViewBuilder(GapicInterfaceContext context) {
    addSmokeTestImports(context.getImportTypeTable());
    SurfaceNamer namer = context.getNamer();
    MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
    SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
    OptionalArrayMethodView apiMethod = createSmokeTestCaseApiMethodView(flattenedMethodContext);
    testClass.apiSettingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
    testClass.apiClassName(context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.apiName(PhpPackageMetadataNamer.getApiNameFromPackageName(context.getNamer().getPackageName()).toLowerUnderscore());
    testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
    testClass.apiMethod(apiMethod);
    testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethod.initCode(), context.getNamer()));
    testClass.methodName(namer.getTestCaseName(new SymbolTable(), method));
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.SYSTEM));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testClass.fileHeader(fileHeader);
    return testClass;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SymbolTable(com.google.api.codegen.util.SymbolTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)15 MethodModel (com.google.api.codegen.config.MethodModel)14 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)10 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 MethodConfig (com.google.api.codegen.config.MethodConfig)6 MethodContext (com.google.api.codegen.transformer.MethodContext)6 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)5 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)5 ImmutableList (com.google.common.collect.ImmutableList)5 ArrayList (java.util.ArrayList)5 InterfaceModel (com.google.api.codegen.config.InterfaceModel)4 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)4 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)4 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)4 SymbolTable (com.google.api.codegen.util.SymbolTable)3 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)3 FieldConfig (com.google.api.codegen.config.FieldConfig)2 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2