Search in sources :

Example 16 with GapicInterfaceContext

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

the class RubyGapicSurfaceTestTransformer method createSmokeTestViews.

// /////////////////////////////////// Smoke Test ///////////////////////////////////////
private List<ViewModel> createSmokeTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> views = 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);
        views.add(createSmokeTestClassView(context));
    }
    return views.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 17 with GapicInterfaceContext

use of com.google.api.codegen.config.GapicInterfaceContext 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 18 with GapicInterfaceContext

use of com.google.api.codegen.config.GapicInterfaceContext 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 19 with GapicInterfaceContext

use of com.google.api.codegen.config.GapicInterfaceContext 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 20 with GapicInterfaceContext

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

the class RubyGapicSurfaceTransformer method generateCredentialsView.

private ViewModel generateCredentialsView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    CredentialsClassView credentialsClass = generateCredentialsClass(model, productConfig);
    ImportSectionView importSection = ImportSectionView.newBuilder().externalImports(ImmutableList.of(ImportFileView.newBuilder().moduleName("googleauth").types(ImmutableList.<ImportTypeView>of()).build())).build();
    List<String> modules = namer.getApiModules();
    InterfaceModel apiInterface = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).findFirst().orElseThrow(() -> new NoSuchElementException("reachable API interfaces"));
    GapicInterfaceContext context = createContext(apiInterface, productConfig);
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    return CredentialsClassFileView.newBuilder().outputPath(namer.getSourceFilePath(subPath, "Credentials")).templateFileName(CREDENTIALS_CLASS_TEMPLATE_FILE).credentialsClass(credentialsClass).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer, ImmutableList.copyOf(modules))).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) CredentialsClassView(com.google.api.codegen.viewmodel.CredentialsClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) NoSuchElementException(java.util.NoSuchElementException) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)32 InterfaceModel (com.google.api.codegen.config.InterfaceModel)28 ViewModel (com.google.api.codegen.viewmodel.ViewModel)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)15 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)15 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)10 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)9 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)9 MethodModel (com.google.api.codegen.config.MethodModel)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)5 ApiMethodView (com.google.api.codegen.viewmodel.ApiMethodView)5 HashSet (java.util.HashSet)4 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 MethodConfig (com.google.api.codegen.config.MethodConfig)2 MethodContext (com.google.api.codegen.config.MethodContext)2 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)2