use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> views = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.UNIT);
views.add(createUnitTestFileView(context));
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
context = createContext(apiInterface, productConfig, PhpSurfaceNamer.TestKind.SYSTEM);
views.add(createSmokeTestClassView(context));
}
}
return views;
}
use of com.google.api.codegen.config.GapicInterfaceContext 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.config.GapicInterfaceContext 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();
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateApiClass.
private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
StaticLangApiView.Builder apiClass = StaticLangApiView.newBuilder();
List<StaticLangApiMethodView> methods = apiMethodTransformer.generateApiMethods(context);
apiClass.doc(serviceTransformer.generateServiceDoc(context, null, context.getProductConfig()));
apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterfaceModel()));
String grpcTypeName = namer.getGrpcServiceClassName(context.getInterfaceModel());
int dotIndex = grpcTypeName.indexOf('.');
apiClass.grpcTypeNameOuter(grpcTypeName.substring(0, dotIndex));
apiClass.grpcTypeNameInner(grpcTypeName.substring(dotIndex + 1, grpcTypeName.length()));
apiClass.settingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
List<ApiCallableView> callables = new ArrayList<>();
for (ApiCallableView call : apiCallableTransformer.generateStaticLangApiCallables(context)) {
if (call.type() == ApiCallableImplType.SimpleApiCallable || call.type() == ApiCallableImplType.BatchingApiCallable || call.type() == ApiCallableImplType.BidiStreamingApiCallable || call.type() == ApiCallableImplType.ServerStreamingApiCallable) {
callables.add(call);
}
}
apiClass.apiCallableMembers(callables);
apiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
apiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
apiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
apiClass.apiMethods(methods);
List<StaticLangApiMethodView> methodsImpl = new ArrayList<>();
for (StaticLangApiMethodView method : methods) {
if (methodTypeHasImpl(method.type())) {
methodsImpl.add(method);
}
}
apiClass.apiMethodsImpl(methodsImpl);
apiClass.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
apiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
apiClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
apiClass.modifyMethods(generateModifyMethods(context));
apiClass.apiHasUnaryMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.NonStreaming));
apiClass.apiHasServerStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ServerStreaming));
apiClass.apiHasClientStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ClientStreaming));
apiClass.apiHasBidiStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.BidiStreaming));
return apiClass.build();
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> models = new ArrayList<>();
GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
models.add(generate(context));
context = GapicInterfaceContext.create(apiInterface, productConfig, createTypeTable(), namer, featureConfig);
models.add(generateExample(context));
}
models.add(generatePackageInfo(model, productConfig, namer));
return models;
}
Aggregations