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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations