Search in sources :

Example 31 with SurfaceNamer

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

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

the class PhpGapicSurfaceTestTransformer method createSmokeTestClassView.

private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
    String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/system").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
    SmokeTestClassView.Builder testClass = createSmokeTestClassViewBuilder(context);
    testClass.name(name);
    testClass.outputPath(namer.getSourceFilePath(outputPath, name));
    return testClass.build();
}
Also used : SmokeTestClassView(com.google.api.codegen.viewmodel.testing.SmokeTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 33 with SurfaceNamer

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

Example 34 with SurfaceNamer

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

the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.

private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
    List<RestInterfaceConfigView> configViews = new ArrayList<>();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    SurfaceNamer namer = context.getNamer();
    Map<String, List<HttpRule>> interfaces = new TreeMap<>();
    Service serviceConfig = serviceModel.getServiceConfig();
    for (MethodModel methodModel : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        Method method = methodContext.getMethod();
        // REST does not support streaming methods
        if (methodConfig.isGrpcStreaming()) {
            continue;
        }
        String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
        HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
        String selector = httpRule.getSelector();
        String interfaceName = selector.substring(0, selector.lastIndexOf("."));
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
        configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
    }
    return configViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 35 with SurfaceNamer

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

the class PhpGapicSurfaceTransformer method buildGapicClientViewModel.

private ViewModel buildGapicClientViewModel(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    addApiImports(context);
    List<ApiMethodView> methods = generateApiMethods(context);
    DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder();
    apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
    apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME);
    apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName());
    String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig());
    apiImplClass.name(implName);
    ProductServiceConfig productServiceConfig = new ProductServiceConfig();
    apiImplClass.serviceAddress(productServiceConfig.getServiceAddress(context.getInterface().getModel()));
    apiImplClass.servicePort(productServiceConfig.getServicePort());
    apiImplClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel()));
    apiImplClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel()));
    apiImplClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    apiImplClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    apiImplClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    apiImplClass.pathTemplateGetterFunctions(pathTemplateTransformer.generatePathTemplateGetterFunctions(context));
    apiImplClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
    apiImplClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
    apiImplClass.batchingDescriptors(ImmutableList.<BatchingDescriptorView>of());
    apiImplClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
    apiImplClass.longRunningDescriptors(createLongRunningDescriptors(context));
    apiImplClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    apiImplClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context));
    apiImplClass.methodKeys(generateMethodKeys(context));
    apiImplClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
    apiImplClass.clientConfigName(namer.getClientConfigName(context.getInterfaceConfig()));
    apiImplClass.interfaceKey(context.getInterface().getFullName());
    String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel());
    apiImplClass.grpcClientTypeName(grpcClientTypeName);
    apiImplClass.apiMethods(methods);
    apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
    apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
    apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
    apiImplClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion());
    // must be done as the last step to catch all imports
    apiImplClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    apiImplClass.outputPath(outputPath + "/" + implName + ".php");
    return apiImplClass.build();
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) ProductServiceConfig(com.google.api.codegen.config.ProductServiceConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)91 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 InterfaceModel (com.google.api.codegen.config.InterfaceModel)18 ImmutableList (com.google.common.collect.ImmutableList)16 ViewModel (com.google.api.codegen.viewmodel.ViewModel)14 ArrayList (java.util.ArrayList)14 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)13 MethodModel (com.google.api.codegen.config.MethodModel)12 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)10 MethodConfig (com.google.api.codegen.config.MethodConfig)9 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)9 ApiModel (com.google.api.codegen.config.ApiModel)8 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)8 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)8 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)8 FieldConfig (com.google.api.codegen.config.FieldConfig)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)5 PackageMetadataNamer (com.google.api.codegen.transformer.PackageMetadataNamer)5