Search in sources :

Example 66 with SurfaceNamer

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

the class RubyGapicSurfaceTestTransformer method createUnitTestViews.

// /////////////////////////////////// Unit Test ///////////////////////////////////////
private List<ClientTestFileView> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ClientTestFileView> views = ImmutableList.builder();
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String testClassName = namer.getUnitTestClassName(context.getInterfaceConfig());
        String outputPath = unitTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), productConfig);
        ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
        views.add(ClientTestFileView.newBuilder().templateFileName(UNIT_TEST_TEMPLATE_FILE).outputPath(namer.getSourceFilePath(outputPath, testClassName)).testClass(createUnitTestClassView(context, model.hasMultipleServices())).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).apiVersion(packageConfig.apiVersion()).build());
    }
    return views.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 67 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateApiClasses.

private List<ViewModel> generateApiClasses(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    FeatureConfig featureConfig = new RubyFeatureConfig();
    ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        String packageName = productConfig.getPackageName();
        ModelTypeTable modelTypeTable = new ModelTypeTable(new RubyTypeTable(productConfig.getPackageName()), new RubyModelTypeNameConverter(packageName));
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
        serviceSurfaces.add(generateApiClass(context, packageName));
    }
    return serviceSurfaces.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfig(com.google.api.codegen.transformer.FeatureConfig) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 68 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateTopLevelIndexView.

private ViewModel generateTopLevelIndexView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    ImmutableList.Builder<VersionIndexRequireView> requireViews = ImmutableList.builder();
    List<String> modules = namer.getTopLevelApiModules();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String clientName = namer.getPackageName();
        String serviceName = namer.getPackageServiceName(context.getInterfaceConfig());
        if (model.hasMultipleServices()) {
            clientName += "::" + serviceName;
        }
        String topLevelNamespace = namer.getTopLevelNamespace();
        String postVersionNamespace = postVersionNamespace(namer);
        requireViews.add(VersionIndexRequireView.newBuilder().clientName(clientName).serviceName(serviceName).fileName(versionPackagePath(namer)).topLevelNamespace(topLevelNamespace).postVersionNamespace(postVersionNamespace).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
    }
    String versionDirBasePath = namer.packageFilePathPiece(Name.upperCamel(modules.get(modules.size() - 1)));
    return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).templateFileName(VERSION_INDEX_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + topLevelPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, false)).type(VersionIndexType.TopLevelIndex).versionDirBasePath(versionDirBasePath).postVersionDirPath(postVersionDirPath(namer)).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Example 69 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateModuleViews.

private List<ModuleView> generateModuleViews(ApiModel model, GapicProductConfig productConfig, boolean includeVersionModule) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    RubyPackageMetadataTransformer metadataTransformer = new RubyPackageMetadataTransformer(packageConfig);
    RubyPackageMetadataNamer packageNamer = new RubyPackageMetadataNamer(productConfig.getPackageName());
    ImmutableList.Builder<ModuleView> moduleViews = ImmutableList.builder();
    for (String moduleName : namer.getApiModules()) {
        boolean isVersion = moduleName.equals(namer.getApiWrapperModuleVersion());
        if ((isVersion && includeVersionModule) || (moduleName.equals(namer.getModuleServiceName()) && !includeVersionModule)) {
            moduleViews.add(metadataTransformer.generateReadmeMetadataView(model, productConfig, packageNamer).moduleName(moduleName).build());
        } else if (includeVersionModule || !isVersion) {
            moduleViews.add(SimpleModuleView.newBuilder().moduleName(moduleName).build());
        }
        if (!includeVersionModule && isVersion) {
            break;
        }
    }
    return moduleViews.build();
}
Also used : ModuleView(com.google.api.codegen.viewmodel.metadata.ModuleView) SimpleModuleView(com.google.api.codegen.viewmodel.metadata.SimpleModuleView) ImmutableList(com.google.common.collect.ImmutableList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 70 with SurfaceNamer

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

the class RubyGapicSurfaceTransformer method generateApiClass.

private ViewModel generateApiClass(GapicInterfaceContext context, String packageName) {
    SurfaceNamer namer = context.getNamer();
    PackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(packageName);
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    String name = namer.getApiWrapperClassName(context.getInterfaceConfig());
    List<ApiMethodView> methods = generateApiMethods(context);
    DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder();
    xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME);
    xapiClass.outputPath(namer.getSourceFilePath(subPath, name));
    xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    xapiClass.protoFilename(context.getInterface().getFile().getSimpleName());
    xapiClass.name(name);
    xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0), context.getProductConfig()));
    xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context));
    ApiModel model = context.getApiModel();
    xapiClass.serviceHostname(productServiceConfig.getServiceHostname(context.getServiceAddress()));
    xapiClass.servicePort(productServiceConfig.getServicePort(context.getServiceAddress()));
    xapiClass.serviceTitle(model.getTitle());
    xapiClass.authScopes(model.getAuthScopes(context.getProductConfig()));
    xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress());
    xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes());
    xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context));
    xapiClass.batchingDescriptors(batchingTransformer.generateDescriptors(context));
    xapiClass.longRunningDescriptors(ImmutableList.<LongRunningOperationDetailView>of());
    xapiClass.grpcStreamingDescriptors(ImmutableList.<GrpcStreamingDetailView>of());
    xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods());
    xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods());
    xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
    xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
    xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
    xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
    xapiClass.pathTemplateGetterFunctions(ImmutableList.<PathTemplateGetterFunctionView>of());
    xapiClass.interfaceKey(context.getInterface().getFullName());
    xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterfaceConfig()));
    xapiClass.grpcClientTypeName(namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), context.getInterfaceModel()));
    xapiClass.supportsGrpcTransport(true);
    xapiClass.apiMethods(methods);
    xapiClass.gapicPackageName(RubyUtil.isLongrunning(context.getProductConfig().getPackageName()) ? "google-gax" : metadataNamer.getMetadataIdentifier());
    xapiClass.fullyQualifiedCredentialsClassName(namer.getFullyQualifiedCredentialsClassName());
    xapiClass.defaultCredentialsInitializerCall(RubyUtil.isLongrunning(context.getProductConfig().getPackageName()) ? "default(scopes: scopes)" : "default");
    return xapiClass.build();
}
Also used : ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) DynamicLangXApiView(com.google.api.codegen.viewmodel.DynamicLangXApiView) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)109 InterfaceModel (com.google.api.codegen.config.InterfaceModel)26 ViewModel (com.google.api.codegen.viewmodel.ViewModel)23 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 ArrayList (java.util.ArrayList)22 ImmutableList (com.google.common.collect.ImmutableList)17 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)15 MethodModel (com.google.api.codegen.config.MethodModel)14 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)13 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)11 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)10 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ApiModel (com.google.api.codegen.config.ApiModel)9 MethodConfig (com.google.api.codegen.config.MethodConfig)9 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)9 DynamicLangXApiView (com.google.api.codegen.viewmodel.DynamicLangXApiView)9 FieldConfig (com.google.api.codegen.config.FieldConfig)8 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)8 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)8