Search in sources :

Example 11 with GapicMethodContext

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

the class PythonPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. 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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        GapicMethodContext methodContext = context.asRequestMethodContext(method);
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(methodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 12 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext 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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Example 13 with GapicMethodContext

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

the class NodeJSSurfaceNamer method getReturnDocLines.

/**
 * Return JSDoc callback comment and return type comment for the given method.
 */
@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
    GapicMethodContext gapicMethodContext = (GapicMethodContext) methodContext;
    GapicMethodConfig methodConfig = (GapicMethodConfig) methodContext.getMethodConfig();
    Method method = methodConfig.getMethod();
    if (method.getRequestStreaming() && method.getResponseStreaming()) {
        return bidiStreamingReturnDocLines(method);
    } else if (method.getResponseStreaming()) {
        return responseStreamingReturnDocLines(method);
    }
    List<String> callbackLines = returnCallbackDocLines(context.getImportTypeTable(), gapicMethodContext);
    List<String> returnObjectLines = returnObjectDocLines(context.getImportTypeTable(), gapicMethodContext);
    return ImmutableList.<String>builder().addAll(callbackLines).addAll(returnObjectLines).build();
}
Also used : GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) GapicMethodConfig(com.google.api.codegen.config.GapicMethodConfig) Method(com.google.api.tools.framework.model.Method)

Example 14 with GapicMethodContext

use of com.google.api.codegen.config.GapicMethodContext 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();
    GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
    FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
    GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, 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(getApiName(context.getProductConfig().getPackageName()));
    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.config.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)

Example 15 with GapicMethodContext

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

the class RubyPackageMetadataTransformer method generateExampleMethods.

// Generates methods used as examples for the README.md file.
// This currently generates a list of methods that have smoke test configuration. 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(productConfig)) {
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
        if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        MethodModel method = interfaceConfig.getSmokeTestConfig().getMethod();
        GapicMethodContext defaultMethodContext = context.asRequestMethodContext(method);
        FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method));
        GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
        exampleMethods.add(createExampleApiMethodView(flattenedMethodContext, model.hasMultipleServices()));
    }
    return exampleMethods.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.config.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.config.GapicInterfaceContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Aggregations

GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)19 MethodModel (com.google.api.codegen.config.MethodModel)18 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)10 ArrayList (java.util.ArrayList)8 SymbolTable (com.google.api.codegen.util.SymbolTable)7 ImmutableList (com.google.common.collect.ImmutableList)7 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)6 TestCaseView (com.google.api.codegen.viewmodel.testing.TestCaseView)6 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)4 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)4 ClientMethodType (com.google.api.codegen.viewmodel.ClientMethodType)4 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)4 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)4 FieldConfig (com.google.api.codegen.config.FieldConfig)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)3 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)3 LongRunningConfig (com.google.api.codegen.config.LongRunningConfig)2