use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicClientTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
CSharpFeatureConfig featureConfig = new CSharpFeatureConfig();
InterfaceModel lastApiInterface = null;
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(productConfig.getPackageName(), ALIAS_MODE), namer, featureConfig);
surfaceDocs.add(generateApiAndSettingsView(context));
lastApiInterface = apiInterface;
}
GapicInterfaceContext context = GapicInterfaceContext.create(lastApiInterface, productConfig, csharpCommonTransformer.createTypeTable(productConfig.getPackageName(), ALIAS_MODE), namer, featureConfig);
surfaceDocs.add(generateResourceNamesView(context));
return surfaceDocs;
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getExamplePackageName(), ALIAS_MODE), namer, new CSharpFeatureConfig());
csharpCommonTransformer.addCommonImports(context);
context.getImportTypeTable().saveNicknameFor("Google.Protobuf.Bytestring");
context.getImportTypeTable().saveNicknameFor("System.Linq.__import__");
surfaceDocs.add(generateSnippets(context));
}
return surfaceDocs;
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName(), ALIAS_MODE);
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getTestPackageName(), ALIAS_MODE), 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));
}
return surfaceDocs;
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class CSharpApiMethodTransformer method generateApiMethods.
@Override
public List<StaticLangApiMethodView> generateApiMethods(InterfaceContext interfaceContext) {
Preconditions.checkArgument(interfaceContext instanceof GapicInterfaceContext, "Only applicable for protobuf-based API in CSharp.");
GapicInterfaceContext context = (GapicInterfaceContext) interfaceContext;
List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
// gRPC streaming methods.
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup).withCallingForms(ImmutableList.of(CallingForm.FlattenedStreamingBidi, CallingForm.FlattenedStreamingServer));
apiMethods.add(generateGrpcStreamingFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), null));
}
}
requestMethodContext = requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestStreamingBidi, CallingForm.RequestStreamingServer));
apiMethods.add(generateGrpcStreamingRequestObjectMethod(requestMethodContext, null));
} else if (requestMethodContext.isLongRunningMethodContext()) {
// LRO methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generateFlattenedLroMethods(methodContext));
}
}
apiMethods.add(generateAsyncOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestAsyncPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), true, null));
apiMethods.add(generateOperationRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.LongRunningRequestPollUntilComplete)), csharpCommonTransformer.callSettingsParam(), null));
} else if (methodConfig.isPageStreaming()) {
// Paged streaming methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generatePageStreamingFlattenedMethods(methodContext, pagedMethodAdditionalParams));
}
}
apiMethods.add(generatePagedRequestObjectAsyncMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestAsyncPaged, CallingForm.RequestAsyncPagedAll, CallingForm.RequestAsyncPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
apiMethods.add(generatePagedRequestObjectMethod(requestMethodContext.withCallingForms(ImmutableList.of(CallingForm.RequestPaged, CallingForm.RequestPagedAll, CallingForm.RequestPagedPageSize)), csharpCommonTransformer.callSettingsParam(), null));
} else {
// Unary methods.
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext, flatteningGroup);
apiMethods.addAll(generateNormalFlattenedMethods(methodContext));
}
}
apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod, null));
apiMethods.add(generateRequestObjectAsyncMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.RequestAsync)), csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod, null));
apiMethods.add(generateRequestObjectMethod(requestMethodContext.withCallingForms(Collections.singletonList(CallingForm.Request)), csharpCommonTransformer.callSettingsParam(), null));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.GapicInterfaceContext in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
GoSurfaceNamer namer = new GoSurfaceNamer(productConfig.getPackageName());
List<ViewModel> models = new ArrayList<ViewModel>();
models.add(generateMockServiceView(model, productConfig, namer));
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface);
if (interfaceConfig == null || interfaceConfig.getSmokeTestConfig() == null) {
continue;
}
GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, GoGapicSurfaceTransformer.createTypeTable(), namer, featureConfig);
models.add(createSmokeTestClassView(context));
}
return models;
}
Aggregations