use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
for (InterfaceModel apiInterface : model.getInterfaces()) {
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getPackageName()), namer, new CSharpFeatureConfig());
csharpCommonTransformer.addCommonImports(context);
ModelTypeTable typeTable = context.getImportTypeTable();
typeTable.saveNicknameFor("Xunit.FactAttribute");
typeTable.saveNicknameFor("Moq.Mock");
if (context.getLongRunningMethods().iterator().hasNext()) {
typeTable.saveNicknameFor("Google.LongRunning.Operations");
}
surfaceDocs.add(generateUnitTest(context));
surfaceDocs.add(generateUnitTestCsproj(context));
}
return surfaceDocs;
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generateExample.
private StaticLangClientExampleFileView generateExample(InterfaceContext context) {
StaticLangClientExampleFileView.Builder view = StaticLangClientExampleFileView.newBuilder();
SurfaceNamer namer = context.getNamer();
InterfaceModel apiInterface = context.getInterfaceModel();
ProductConfig productConfig = context.getProductConfig();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
view.templateFileName(SAMPLE_TEMPLATE_FILENAME);
String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
String fileName = namer.getExampleFileName(context.getInterfaceConfig());
view.outputPath(outputPath + File.separator + fileName);
view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
view.clientConstructorExampleName(namer.getApiWrapperClassConstructorExampleName(interfaceConfig));
view.apiMethods(generateApiMethods(context, context.getPublicMethods()));
view.iamResources(iamResourceTransformer.generateIamResources(context));
// Examples are different from the API. In particular, we use short declaration
// and so we omit most type names. We only need
// - Context, to initialize the client
// - The VKit generated library, that's what the sample is for
// - The input types of the methods, to initialize the requests
// So, we clear all imports; addXExampleImports will add back the ones we want.
context.getImportTypeTable().getImports().clear();
addXExampleImports(context, context.getPublicMethods());
view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return view.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method generate.
private StaticLangClientFileView generate(GapicInterfaceContext context) {
StaticLangClientFileView.Builder view = StaticLangClientFileView.newBuilder();
SurfaceNamer namer = context.getNamer();
ApiModel model = context.getApiModel();
ProtoInterfaceModel apiInterface = context.getInterfaceModel();
GapicProductConfig productConfig = context.getProductConfig();
GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
view.templateFileName(API_TEMPLATE_FILENAME);
view.serviceDoc(serviceTransformer.generateServiceDoc(context, null, productConfig));
view.domainLayerLocation(productConfig.getDomainLayerLocation());
view.clientTypeName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
view.clientConstructorName(namer.getApiWrapperClassConstructorName(interfaceConfig));
view.defaultClientOptionFunctionName(namer.getDefaultApiSettingsFunctionName(interfaceConfig));
view.defaultCallOptionFunctionName(namer.getDefaultCallSettingsFunctionName(interfaceConfig));
view.callOptionsTypeName(namer.getCallSettingsTypeName(interfaceConfig));
view.serviceOriginalName(model.getTitle());
view.servicePhraseName(namer.getServicePhraseName(interfaceConfig));
String outputPath = pathMapper.getOutputPath(apiInterface.getFullName(), productConfig);
String fileName = namer.getServiceFileName(context.getInterfaceConfig());
view.outputPath(outputPath + File.separator + fileName);
List<RetryConfigDefinitionView> retryDef = generateRetryConfigDefinitions(context, context.getSupportedMethods());
view.retryPairDefinitions(retryDef);
view.callSettings(apiCallableTransformer.generateCallSettings(context));
List<StaticLangApiMethodView> apiMethods = generateApiMethods(context, context.getSupportedMethods());
view.apiMethods(apiMethods);
// If any methods have header request params, "fmt" is needed for `fmt.Sprintf` calls.
if (apiMethods.stream().anyMatch(m -> !m.headerRequestParams().isEmpty())) {
context.getImportTypeTable().saveNicknameFor("fmt;;;");
}
view.iamResources(iamResourceTransformer.generateIamResources(context));
if (!((GapicInterfaceConfig) productConfig.getInterfaceConfig(apiInterface.getFullName())).getIamResources().isEmpty()) {
context.getImportTypeTable().saveNicknameFor("cloud.google.com/go/iam;;;");
}
// In Go, multiple methods share the same iterator type, one iterator type per resource type.
// We have to dedupe the iterators.
Map<String, PageStreamingDescriptorClassView> iterators = new TreeMap<>();
for (PageStreamingDescriptorClassView desc : pageStreamingTransformer.generateDescriptorClasses(context)) {
iterators.put(desc.typeName(), desc);
}
view.pageStreamingDescriptorClasses(new ArrayList<>(iterators.values()));
// Same with long running operations.
Map<String, LongRunningOperationDetailView> lros = new TreeMap<>();
for (StaticLangApiMethodView apiMethod : apiMethods) {
LongRunningOperationDetailView lro = apiMethod.operationMethod();
if (lro != null) {
lros.put(lro.clientReturnTypeName(), lro);
}
}
view.lroDetailViews(new ArrayList<>(lros.values()));
view.serviceAddress(context.getApiModel().getServiceAddress());
view.servicePort(model.getServicePort());
view.stubs(grpcStubTransformer.generateGrpcStubs(context));
addXApiImports(context, context.getSupportedMethods());
view.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return view.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createMockServiceImplFileView.
private MockServiceImplFileView createMockServiceImplFileView(InterfaceContext context) {
addMockServiceImplImports(context);
SurfaceNamer namer = context.getNamer();
String outputPath = pathMapper.getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
String name = namer.getMockGrpcServiceImplName(context.getInterfaceModel());
String grpcClassName = context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcServiceClassName(context.getInterfaceModel()));
MockServiceImplFileView.Builder mockServiceImplFile = MockServiceImplFileView.newBuilder();
mockServiceImplFile.serviceImpl(MockServiceImplView.newBuilder().name(name).mockGrpcClassName(grpcClassName).grpcMethods(mockServiceTransformer.createMockGrpcMethodViews(context)).build());
mockServiceImplFile.outputPath(namer.getSourceFilePath(outputPath, name));
mockServiceImplFile.templateFileName(MOCK_SERVICE_IMPL_FILE);
// Imports must be done as the last step to catch all imports.
FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context);
mockServiceImplFile.fileHeader(fileHeader);
return mockServiceImplFile.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method addUnitTestImports.
// ///////////////////////////////// Imports //////////////////////////////////////
private void addUnitTestImports(InterfaceContext context) {
ImportTypeTable typeTable = context.getImportTypeTable();
typeTable.saveNicknameFor("com.google.api.gax.rpc.InvalidArgumentException");
typeTable.saveNicknameFor("com.google.common.collect.Lists");
typeTable.saveNicknameFor("java.io.IOException");
typeTable.saveNicknameFor("java.util.Arrays");
typeTable.saveNicknameFor("java.util.List");
typeTable.saveNicknameFor("org.junit.After");
typeTable.saveNicknameFor("org.junit.AfterClass");
typeTable.saveNicknameFor("org.junit.Assert");
typeTable.saveNicknameFor("org.junit.BeforeClass");
typeTable.saveNicknameFor("org.junit.Test");
if (context.getInterfaceConfig().hasLongRunningOperations()) {
typeTable.saveNicknameFor("com.google.protobuf.Any");
}
switch(context.getProductConfig().getTransportProtocol()) {
case GRPC:
typeTable.saveNicknameFor("com.google.api.gax.core.NoCredentialsProvider");
typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiClientHeaderProvider");
typeTable.saveNicknameFor("com.google.api.gax.rpc.StatusCode");
typeTable.saveNicknameFor("com.google.api.gax.grpc.GaxGrpcProperties");
typeTable.saveNicknameFor("com.google.api.gax.grpc.GrpcStatusCode");
typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.LocalChannelProvider");
typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockGrpcService");
typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockServiceHelper");
typeTable.saveNicknameFor("com.google.protobuf.GeneratedMessageV3");
typeTable.saveNicknameFor("io.grpc.Status");
typeTable.saveNicknameFor("io.grpc.StatusRuntimeException");
typeTable.saveNicknameFor("java.util.ArrayList");
typeTable.saveNicknameFor("java.util.Objects");
typeTable.saveNicknameFor("java.util.concurrent.ExecutionException");
typeTable.saveNicknameFor("org.junit.Before");
break;
case HTTP:
typeTable.saveNicknameFor("com.google.api.gax.httpjson.ApiMethodDescriptor");
typeTable.saveNicknameFor("com.google.api.gax.httpjson.GaxHttpJsonProperties");
typeTable.saveNicknameFor("com.google.api.gax.httpjson.testing.MockHttpService");
typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiClientHeaderProvider");
typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiException");
typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiExceptionFactory");
typeTable.saveNicknameFor("com.google.api.gax.rpc.StatusCode.Code");
typeTable.saveNicknameFor("com.google.api.gax.rpc.testing.FakeStatusCode");
typeTable.saveNicknameFor("com.google.common.collect.ImmutableList");
// Import stub settings class in unit test file.
SurfaceNamer stubNamer = context.getNamer().cloneWithPackageName(context.getNamer().getStubPackageName());
TypeName rpcStubClassName = stubNamer.getTypeNameConverter().getTypeNameInImplicitPackage(stubNamer.getApiStubSettingsClassName(context.getInterfaceConfig()));
rpcStubClassName.getAndSaveNicknameIn(typeTable.getTypeTable());
break;
}
}
Aggregations