use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable modelTypeTable = new ModelTypeTable(new PhpTypeTable(productConfig.getPackageName()), new PhpModelTypeNameConverter(productConfig.getPackageName()));
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, new PhpSurfaceNamer(productConfig.getPackageName()), new PhpFeatureConfig());
surfaceDocs.addAll(transform(context));
}
return surfaceDocs;
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createSmokeTestViews.
private List<ViewModel> createSmokeTestViews(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
SurfaceNamer surfacePackageNamer = new PythonSurfaceNamer(productConfig.getPackageName());
SurfaceNamer testPackageNamer = new PythonSurfaceNamer(surfacePackageNamer.getTestPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
models.add(createSmokeTestClassView(context, testPackageNamer));
}
}
return models.build();
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PythonGapicSurfaceTestTransformer method createUnitTestViews.
private List<ViewModel> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> models = ImmutableList.builder();
SurfaceNamer surfacePackageNamer = new PythonSurfaceNamer(productConfig.getPackageName());
SurfaceNamer testPackageNamer = new PythonSurfaceNamer(surfacePackageNamer.getTestPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
ModelTypeTable typeTable = createTypeTable(surfacePackageNamer.getTestPackageName());
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, featureConfig);
String testClassName = surfacePackageNamer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView testClassView = ClientTestClassView.newBuilder().apiSettingsClassName(surfacePackageNamer.getNotImplementedString("PythonGapicSurfaceTestTransformer.createUnitTestViews - apiSettingsClassName")).apiClassName(surfacePackageNamer.getApiWrapperClassName(context.getInterfaceConfig())).apiVariableName(surfacePackageNamer.getApiWrapperModuleName()).name(testClassName).apiName(surfacePackageNamer.publicClassName(Name.upperCamelKeepUpperAcronyms(context.getInterfaceModel().getSimpleName()))).testCases(createTestCaseViews(context)).apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations()).apiHasUnaryUnaryMethod(hasUnaryUnary(context.getInterfaceConfig())).apiHasUnaryStreamingMethod(hasUnaryStreaming(context.getInterfaceConfig())).apiHasStreamingUnaryMethod(hasStreamingUnary(context.getInterfaceConfig())).apiHasStreamingStreamingMethod(hasStreamingStreaming(context.getInterfaceConfig())).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(ImmutableList.<MockServiceUsageView>of()).build();
String version = packageConfig.apiVersion();
String filename = surfacePackageNamer.classFileNameBase(Name.upperCamel(testClassName).join(version)) + ".py";
String outputPath = Joiner.on(File.separator).join("tests", "unit", "gapic", version, filename);
ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
models.add(ClientTestFileView.newBuilder().templateFileName(TEST_TEMPLATE_FILE).outputPath(outputPath).testClass(testClassView).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, testPackageNamer)).build());
}
return models.build();
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
// TODO(andrealin): Remove the ProtoApiModel cast.
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> views = ImmutableList.builder();
views.addAll(generateServiceSurfaces(model, productConfig));
views.addAll(generateVersionedDirectoryViews(model, productConfig));
views.addAll(generateTopLevelViews(model, productConfig));
return views.build();
}
use of com.google.api.codegen.viewmodel.ViewModel in project toolkit by googleapis.
the class PythonPackageMetadataTransformer method computeInitFiles.
/**
* Determines which __init__.py files to generate given a list of Python packages. Each Python
* package corresponds to exactly one __init__.py file, although the contents of that file depend
* on whether the package is a namespace package.
*/
private List<ViewModel> computeInitFiles(List<String> packages, SurfaceNamer namer, GapicProductConfig productConfig) {
List<ViewModel> initFiles = new ArrayList<>();
for (String packageName : packages) {
final String template;
if (isNamespacePackage(packageName)) {
template = NAMESPACE_INIT_TEMPLATE_FILE;
} else if (isVersionedDirectoryPackage(namer, packageName)) {
continue;
} else {
template = INIT_TEMPLATE_FILE;
}
String outputPath = Paths.get(packageName.replace(".", File.separator)).resolve("__init__.py").toString();
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), new PythonSurfaceNamer(productConfig.getPackageName()));
initFiles.add(SimpleInitFileView.create(template, outputPath, fileHeader));
}
return initFiles;
}
Aggregations