use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateApiMethods.
private List<StaticLangApiMethodView> generateApiMethods(GapicInterfaceContext context) {
List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isGrpcStreaming()) {
// Only for protobuf-based APIs.
apiMethods.add(apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(requestMethodContext));
} else if (methodConfig.isLongRunningOperation()) {
// Only for protobuf-based APIs.
GapicMethodContext gapicMethodContext = (GapicMethodContext) requestMethodContext;
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext.getMethodModel(), flatteningGroup);
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncOperationFlattenedCallSettingsMethod, true));
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncOperationFlattenedCancellationMethod, true));
apiMethods.add(apiMethodTransformer.generateOperationFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam()));
}
}
apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam(), true));
apiMethods.add(apiMethodTransformer.generateOperationRequestObjectMethod(gapicMethodContext, csharpCommonTransformer.callSettingsParam()));
} else if (methodConfig.isPageStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, pagedMethodAdditionalParams));
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(methodContext, pagedMethodAdditionalParams));
}
}
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
} else {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateFlattenedAsyncMethod(methodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.FlattenedAsyncCallSettingsMethod));
apiMethods.add(apiMethodTransformer.generateFlattenedAsyncMethod(methodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.FlattenedAsyncCancellationTokenMethod));
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam()));
}
}
apiMethods.add(apiMethodTransformer.generateRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod));
apiMethods.add(apiMethodTransformer.generateRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod));
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class CSharpGapicSmokeTestTransformer method generateSmokeTestViewBuilder.
private SmokeTestClassView.Builder generateSmokeTestViewBuilder(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
String name = namer.getSmokeTestClassName(context.getInterfaceConfig());
SmokeTestClassView.Builder smokeTestBuilder = SmokeTestClassView.newBuilder();
SmokeTestConfig smokeTestConfig = context.getInterfaceConfig().getSmokeTestConfig();
if (smokeTestConfig == null) {
return null;
}
MethodModel method = smokeTestConfig.getMethod();
FlatteningConfig flatteningGroup = testCaseTransformer.getSmokeTestFlatteningGroup(context.getMethodConfig(method), context.getInterfaceConfig().getSmokeTestConfig());
GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
smokeTestBuilder.name(name);
smokeTestBuilder.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
smokeTestBuilder.apiSettingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
StaticLangApiMethodView apiMethodView = createSmokeTestCaseApiMethodView(context, methodContext);
smokeTestBuilder.apiMethod(apiMethodView);
smokeTestBuilder.requireProjectId(testCaseTransformer.requireProjectIdInSmokeTest(apiMethodView.initCode(), namer));
// must be done as the last step to catch all imports
smokeTestBuilder.fileHeader(fileHeaderTransformer.generateFileHeader(context));
return smokeTestBuilder;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class CSharpGapicSnippetsTransformer method generateMethods.
private List<StaticLangApiMethodSnippetView> generateMethods(InterfaceContext context) {
List<StaticLangApiMethodSnippetView> methods = new ArrayList<>();
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext methodContext = context.asRequestMethodContext(method);
if (methodConfig.isGrpcStreaming()) {
methods.add(generateGrpcStreamingRequestMethod(methodContext));
} else if (methodConfig.isLongRunningOperation()) {
if (methodConfig.isFlattening()) {
ImmutableList<FlatteningConfig> flatteningGroups = methodConfig.getFlatteningConfigs();
boolean requiresNameSuffix = flatteningGroups.size() > 1;
for (int i = 0; i < flatteningGroups.size(); i++) {
FlatteningConfig flatteningGroup = flatteningGroups.get(i);
String nameSuffix = requiresNameSuffix ? Integer.toString(i + 1) : "";
MethodContext methodContextFlat = context.asFlattenedMethodContext(method, flatteningGroup);
methods.add(generateOperationFlattenedAsyncMethod(methodContextFlat, nameSuffix));
methods.add(generateOperationFlattenedMethod(methodContextFlat, nameSuffix));
}
}
methods.add(generateOperationRequestAsyncMethod(methodContext));
methods.add(generateOperationRequestMethod(methodContext));
} else if (methodConfig.isPageStreaming()) {
if (methodConfig.isFlattening()) {
ImmutableList<FlatteningConfig> flatteningGroups = methodConfig.getFlatteningConfigs();
// Find flattenings that have ambiguous parameters, and mark them to use named arguments.
// Ambiguity occurs in a page-stream flattening that has one or two extra string
// parameters (that are not resource-names) compared to any other flattening of this same
// method.
// Create a string for each flattening, encoding which parameters are strings and
// not-strings. Each character in the string refers to a parameter. Each string refers
// to a flattening.
String[] stringParams = flatteningGroups.stream().map(flat -> flat.getFlattenedFieldConfigs().values().stream().map(field -> field.getField().getType().isStringType() && field.getResourceNameConfig() == null ? 's' : '.').collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString()).toArray(String[]::new);
// Array of which flattenings need to use named arguments.
// Each array entry refers to the correspondingly indexed flattening.
Boolean[] requiresNamedParameters = Arrays.stream(stringParams).map(a -> Arrays.stream(stringParams).anyMatch(b -> a.startsWith(b + "s") || a.startsWith(b + "ss"))).toArray(Boolean[]::new);
boolean requiresNameSuffix = flatteningGroups.size() > 1;
// Build method list.
for (int i = 0; i < flatteningGroups.size(); i++) {
FlatteningConfig flatteningGroup = flatteningGroups.get(i);
String nameSuffix = requiresNameSuffix ? Integer.toString(i + 1) : "";
MethodContext methodContextFlat = context.asFlattenedMethodContext(method, flatteningGroup);
methods.add(generatePagedFlattenedAsyncMethod(methodContextFlat, nameSuffix, requiresNamedParameters[i]));
methods.add(generatePagedFlattenedMethod(methodContextFlat, nameSuffix, requiresNamedParameters[i]));
}
}
methods.add(generatePagedRequestAsyncMethod(methodContext));
methods.add(generatePagedRequestMethod(methodContext));
} else {
if (methodConfig.isFlattening()) {
ImmutableList<FlatteningConfig> flatteningGroups = methodConfig.getFlatteningConfigs();
boolean requiresNameSuffix = flatteningGroups.size() > 1;
for (int i = 0; i < flatteningGroups.size(); i++) {
FlatteningConfig flatteningGroup = flatteningGroups.get(i);
String nameSuffix = requiresNameSuffix ? Integer.toString(i + 1) : "";
MethodContext methodContextFlat = context.asFlattenedMethodContext(method, flatteningGroup);
methods.add(generateFlattenedAsyncMethod(methodContextFlat, nameSuffix));
methods.add(generateFlattenedMethod(methodContextFlat, nameSuffix));
}
}
methods.add(generateRequestAsyncMethod(methodContext));
methods.add(generateRequestMethod(methodContext));
}
}
return methods;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class CSharpGapicUnitTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
// TODO: Add support for streaming methods
} else if (methodConfig.isFlattening()) {
ClientMethodType clientMethodTypeSync;
ClientMethodType clientMethodTypeAsync;
if (methodConfig.isPageStreaming()) {
// TODO: Add support for page-streaming methods
continue;
} else if (methodConfig.isLongRunningOperation()) {
// TODO: Add support for LRO methods
continue;
} else {
clientMethodTypeSync = ClientMethodType.FlattenedMethod;
clientMethodTypeAsync = ClientMethodType.FlattenedAsyncCallSettingsMethod;
}
if (methodConfig.getRerouteToGrpcInterface() != null) {
// TODO: Add support for rerouted methods
continue;
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeSync, Synchronicity.Sync));
testCaseViews.add(createFlattenedTestCase(methodContext, testNameTable, flatteningGroup.getFlattenedFieldConfigs().values(), clientMethodTypeAsync, Synchronicity.Async));
}
GapicMethodContext requestContext = context.asRequestMethodContext(method);
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
} else {
if (methodConfig.isPageStreaming() || methodConfig.isLongRunningOperation() || methodConfig.getRerouteToGrpcInterface() != null) {
// TODO: Add support for page-streaming, LRO, and rerouted methods
continue;
}
GapicMethodContext requestContext = context.asRequestMethodContext(method);
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Sync));
testCaseViews.add(createRequestObjectTestCase(requestContext, methodConfig, testNameTable, Synchronicity.Async));
}
}
return testCaseViews;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class GoGapicSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(GapicInterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = ClientMethodType.RequestObjectMethod;
if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedRequestObjectMethod;
} else if (methodContext.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationRequestObjectMethod;
}
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
return testCaseViews;
}
Aggregations