use of com.google.api.codegen.transformer.GapicInterfaceContext in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateServiceSurfaces.
private Iterable<ViewModel> generateServiceSurfaces(Model model, GapicProductConfig productConfig) {
ModelTypeTable modelTypeTable = new ModelTypeTable(new PythonTypeTable(productConfig.getPackageName()), new PythonModelTypeNameConverter(productConfig.getPackageName()));
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
FeatureConfig featureConfig = new DefaultFeatureConfig();
ProtoApiModel apiModel = new ProtoApiModel(model);
ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
for (InterfaceModel apiInterface : apiModel.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
addApiImports(context);
serviceSurfaces.add(generateApiClass(context));
}
GrpcDocView enumFile = generateEnumView(productConfig, modelTypeTable, namer, model.getFiles());
if (!enumFile.elementDocs().isEmpty()) {
serviceSurfaces.add(enumFile);
}
return serviceSurfaces.build();
}
use of com.google.api.codegen.transformer.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()) {
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.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()) {
GapicInterfaceContext context = createContext(apiInterface, productConfig);
String clientName = namer.getPackageName();
String serviceName = namer.getPackageServiceName(context.getInterfaceConfig());
if (model.hasMultipleServices()) {
clientName += "::" + serviceName;
}
String topLevelNamespace = namer.getTopLevelNamespace();
requireViews.add(VersionIndexRequireView.newBuilder().clientName(clientName).serviceName(serviceName).fileName(versionPackagePath(namer)).topLevelNamespace(topLevelNamespace).doc(serviceTransformer.generateServiceDoc(context, generateApiMethods(context).get(0), productConfig)).build());
}
String versionFileBasePath = namer.packageFilePathPiece(Name.upperCamel(modules.get(modules.size() - 1)));
return VersionIndexView.newBuilder().apiVersion(packageConfig.apiVersion()).requireViews(requireViews.build()).templateFileName(VERSION_INDEX_TEMPLATE_FILE).packageVersion(packageConfig.generatedPackageVersionBound(TargetLanguage.RUBY).lower()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer)).outputPath("lib" + File.separator + topLevelPackagePath(namer) + ".rb").modules(generateModuleViews(model, productConfig, false)).type(VersionIndexType.TopLevelIndex).versionFileBasePath(versionFileBasePath).toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()).build();
}
use of com.google.api.codegen.transformer.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()) {
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.GapicInterfaceContext in project toolkit by googleapis.
the class RubyImportSectionTransformer method generateImportSection.
@Override
public ImportSectionView generateImportSection(TransformationContext transformationContext, String className) {
// TODO support non-Gapic inputs
GapicInterfaceContext context = (GapicInterfaceContext) transformationContext;
Set<String> importFilenames = generateImportFilenames(context);
ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
importSection.standardImports(generateStandardImports());
importSection.externalImports(generateExternalImports(context));
importSection.appImports(generateAppImports(context, importFilenames));
importSection.serviceImports(generateServiceImports(context, importFilenames));
return importSection.build();
}
Aggregations