use of com.google.api.codegen.viewmodel.FileHeaderView 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;
}
use of com.google.api.codegen.viewmodel.FileHeaderView in project toolkit by googleapis.
the class RubyGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(GapicInterfaceContext context) {
boolean packageHasMultipleServices = context.getApiModel().hasMultipleServices();
String outputPath = smokeTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
RubyPackageMetadataNamer metadataNamer = new RubyPackageMetadataNamer(context.getNamer().getPackageName());
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
TestCaseTransformer testCaseTransformer = new TestCaseTransformer(valueProducer, packageHasMultipleServices);
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
OptionalArrayMethodView apiMethodView = createSmokeTestCaseApiMethodView(flattenedMethodContext, packageHasMultipleServices);
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(name);
testClass.outputPath(namer.getSourceFilePath(outputPath, name));
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
testClass.projectIdVariableName(metadataNamer.getProjectVariable(true));
testClass.apiVersion(packageConfig.apiVersion());
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSectionTransformer.generateSmokeTestImportSection(context), namer);
testClass.fileHeader(fileHeader);
return testClass.build();
}
use of com.google.api.codegen.viewmodel.FileHeaderView in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method generateUnitTestBuilder.
private ClientTestFileView.Builder generateUnitTestBuilder(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
String name = namer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.apiVariableName("client");
testClass.name(name);
testClass.testCases(createTestCaseViews(context));
testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
testClass.grpcServiceClassName(namer.getGrpcServiceClassName(context.getInterfaceModel()));
testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
testClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
testClass.hasLongRunningOperations(context.getLongRunningMethods().iterator().hasNext());
ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
testFile.testClass(testClass.build());
// Imports must be done as the last step to catch all imports.
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testFile.fileHeader(fileHeader);
return testFile;
}
use of com.google.api.codegen.viewmodel.FileHeaderView in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method createSmokeTestClassView.
private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) {
SurfaceNamer namer = context.getNamer();
MethodModel method = context.getInterfaceConfig().getSmokeTestConfig().getMethod();
MethodContext methodContext = context.asRequestMethodContext(method);
SmokeTestClassView.Builder testClass = SmokeTestClassView.newBuilder();
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(methodContext);
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(namer.getSmokeTestClassName(context.getInterfaceConfig()));
testClass.outputPath(context.getProductConfig().getPackageName() + File.separator + method.getSimpleName() + "_smoke_test.go");
testClass.templateFileName(SMOKE_TEST_TEMPLATE_FILE);
testClass.apiMethod(apiMethodView);
testClass.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), context.getNamer()));
// The shared code above add imports both for input and output.
// Since we use short decls, we don't need to import anything for output.
context.getImportTypeTable().getImports().clear();
method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testClass.fileHeader(fileHeader);
return testClass.build();
}
use of com.google.api.codegen.viewmodel.FileHeaderView in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createUnitTestFileView.
// /////////////////////////////////// Unit Test /////////////////////////////////////////
private ClientTestFileView createUnitTestFileView(InterfaceContext context) {
addUnitTestImports(context);
String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
String name = namer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
testClass.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
testClass.apiStubSettingsClassName(namer.getApiStubSettingsClassName(context.getInterfaceConfig()));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(name);
testClass.testCases(createTestCaseViews(context));
testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
testFile.testClass(testClass.build());
testFile.outputPath(namer.getSourceFilePath(outputPath, name));
testFile.templateFileName(unitTestTemplateFile);
// Imports must be done as the last step to catch all imports.
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
testFile.fileHeader(fileHeader);
return testFile.build();
}
Aggregations