use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method createUnitTestFileView.
private ClientTestFileView createUnitTestFileView(GapicInterfaceContext context) {
addUnitTestImports(context.getImportTypeTable());
String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/Unit").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
SurfaceNamer namer = context.getNamer();
String name = namer.getUnitTestClassName(context.getInterfaceConfig());
ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
testClass.apiSettingsClassName(namer.getNotImplementedString("PhpGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName"));
testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
testClass.name(name);
testClass.apiName(getApiName(context.getProductConfig().getPackageName()));
testClass.testCases(createTestCaseViews(context));
// Add gRPC client imports.
for (InterfaceModel grpcInterface : mockServiceTransformer.getGrpcInterfacesForService(context.getApiModel(), context.getProductConfig(), context.getInterfaceModel()).values()) {
context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcClientTypeName(grpcInterface));
}
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(UNIT_TEST_TEMPLATE_FILE);
ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.UNIT));
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
testFile.fileHeader(fileHeader);
return testFile.build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonSampleImportTransformer method generateImportSection.
public ImportSectionView generateImportSection(MethodContext context, CallingForm form, OutputContext outputContext, ImportTypeTable initCodeTypeTable, Iterable<InitCodeNode> nodes) {
ImportSectionView.Builder imports = ImportSectionView.newBuilder();
ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
// First get all the imports generated from InitCodeTransformer
List<ImportFileView> initCodeAppImports = importSectionTransformer.generateImportSection(context, nodes).appImports();
appImports.addAll(initCodeAppImports);
// Then add more imports that other parts of the sample need
// For now we only need to special-case `enums`
boolean addEnumImports = outputContext.stringFormattedVariableTypes().stream().anyMatch(TypeModel::isEnum) || Streams.stream(nodes).map(InitCodeNode::getType).anyMatch(TypeModel::isEnum);
if (addEnumImports) {
ImportTypeView importTypeView = ImportTypeView.newBuilder().fullName("enums").type(ImportType.SimpleImport).nickname("").build();
ImportFileView enumImportView = ImportFileView.newBuilder().moduleName(context.getNamer().getVersionedDirectoryNamespace()).types(Collections.singletonList(importTypeView)).build();
if (!initCodeAppImports.contains(enumImportView)) {
appImports.add(enumImportView);
}
}
return imports.appImports(appImports.build()).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method generateMockServiceView.
private MockCombinedView generateMockServiceView(ApiModel model, GapicProductConfig productConfig, SurfaceNamer namer) {
ModelTypeTable typeTable = GoGapicSurfaceTransformer.createTypeTable();
List<MockServiceImplView> impls = new ArrayList<>();
List<ClientTestClassView> testClasses = new ArrayList<>();
for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
impls.add(MockServiceImplView.newBuilder().mockGrpcClassName(namer.getGrpcServerTypeName(apiInterface)).name(namer.getMockGrpcServiceImplName(apiInterface)).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
}
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
// We don't need any import here.
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, typeTable, namer, featureConfig);
testClasses.add(ClientTestClassView.newBuilder().apiSettingsClassName(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - apiSettingsClassName")).apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig())).name(namer.getNotImplementedString("GoGapicSurfaceTestTransformer.generateMockServiceView - name")).testCases(createTestCaseViews(context)).missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress()).missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes()).mockServices(Collections.emptyList()).build());
}
ImportSectionView importSection = importSectionTransformer.generateImportSection(typeTable.getImports());
return MockCombinedView.newBuilder().outputPath(productConfig.getPackageName() + File.separator + "mock_test.go").serviceImpls(impls).testClasses(testClasses).templateFileName(MOCK_SERVICE_TEMPLATE_FILE).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).mockServices(mockServiceTransformer.createMockServices(namer, model, productConfig)).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateVersionedInitView.
private ViewModel generateVersionedInitView(ProtoApiModel apiModel, GapicProductConfig productConfig) {
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
boolean packageHasEnums = packageHasEnums(apiModel.getProtoModel());
ImportSectionView imports = importSectionTransformer.generateVersionedInitImportSection(apiModel, productConfig, namer, packageHasEnums);
return VersionIndexView.newBuilder().templateFileName(VERSIONED_INIT_TEMPLATE_FILENAME).outputPath(versionedInitOutputFile(namer)).requireViews(versionedInitRequireViews(apiModel, productConfig, namer)).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).packageHasEnums(packageHasEnums).build();
}
use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.
the class PythonGapicSurfaceTransformer method generateServiceSurfaces.
private Iterable<ViewModel> generateServiceSurfaces(ProtoApiModel apiModel, GapicProductConfig productConfig) {
ModelTypeTable modelTypeTable = new ModelTypeTable(new PythonTypeTable(productConfig.getPackageName()), new PythonModelTypeNameConverter(productConfig.getPackageName()));
SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
FeatureConfig featureConfig = new DefaultFeatureConfig();
ImmutableList.Builder<ViewModel> serviceSurfaces = ImmutableList.builder();
for (InterfaceModel apiInterface : apiModel.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, namer, featureConfig);
addApiImports(context);
String subPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
DynamicLangXApiView.Builder serviceClass = generateApiView(context);
serviceClass.templateFileName(XAPI_TEMPLATE_FILENAME);
serviceClass.outputPath(namer.getSourceFilePath(subPath, namer.getApiWrapperClassName(context.getInterfaceConfig())));
serviceClass.fileHeader(fileHeaderTransformer.generateFileHeader(context));
serviceSurfaces.add(serviceClass.build());
DynamicLangXApiView.Builder grpcTransportClass = generateApiView(context);
grpcTransportClass.templateFileName(TRANSPORT_TEMPLATE_FILENAME);
grpcTransportClass.outputPath(namer.getSourceFilePath(subPath + "/transports", namer.getGrpcTransportClassName(context.getInterfaceConfig())));
ImportSectionView grpcTransportImportSection = importSectionTransformer.generateGrpcTransportImportSection(context);
grpcTransportClass.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, grpcTransportImportSection, namer));
serviceSurfaces.add(grpcTransportClass.build());
}
GrpcDocView enumFile = generateEnumView(productConfig, modelTypeTable, namer, apiModel.getProtoModel().getFiles());
if (!enumFile.elementDocs().isEmpty()) {
serviceSurfaces.add(enumFile);
}
return serviceSurfaces.build();
}
Aggregations