use of com.google.api.codegen.config.MethodConfig 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.MethodConfig in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createSmokeTestCaseApiMethodView.
private StaticLangApiMethodView createSmokeTestCaseApiMethodView(MethodContext methodContext) {
MethodConfig methodConfig = methodContext.getMethodConfig();
StaticLangApiMethodView initialApiMethodView;
if (methodConfig.isPageStreaming()) {
if (methodContext.isFlattenedMethodContext()) {
initialApiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext);
} else {
throw new UnsupportedOperationException("Unsupported smoke test type: page-streaming + request-object");
}
} else if (methodConfig.isGrpcStreaming()) {
throw new UnsupportedOperationException("Unsupported smoke test type: grpc-streaming");
} else if (methodConfig.isLongRunningOperation()) {
if (methodContext.isFlattenedMethodContext()) {
initialApiMethodView = apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext);
} else {
throw new UnsupportedOperationException("Unsupported smoke test type: long-running + request-object");
}
} else {
if (methodContext.isFlattenedMethodContext()) {
initialApiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext);
} else {
throw new UnsupportedOperationException("Unsupported smoke test type: simple-call + request-object");
}
}
StaticLangApiMethodView.Builder apiMethodView = initialApiMethodView.toBuilder();
InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
apiMethodView.initCode(initCodeView);
return apiMethodView.build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateApiMethods.
private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isPageStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
} else if (methodConfig.isGrpcStreaming()) {
ImportTypeTable typeTable = context.getImportTypeTable();
switch(methodConfig.getGrpcStreamingType()) {
case BidiStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
break;
case ClientStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
break;
case ServerStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
break;
default:
throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
}
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else if (methodConfig.isLongRunningOperation()) {
context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
}
}
return apiMethods;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PhpApiMethodParamTransformer method getMethodParamDocs.
private List<ParamDocView> getMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
if (context.getMethodModel().getRequestStreaming()) {
return ImmutableList.of();
}
MethodConfig methodConfig = context.getMethodConfig();
ImmutableList.Builder<ParamDocView> paramDocs = ImmutableList.builder();
for (FieldModel field : fields) {
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
paramDoc.paramName(context.getNamer().getVariableName(field));
paramDoc.typeName(context.getTypeTable().getAndSaveNicknameFor(field));
ImmutableList.Builder<String> docLines = ImmutableList.builder();
if (methodConfig.isPageStreaming() && methodConfig.getPageStreaming().hasPageSizeField() && field.equals(methodConfig.getPageStreaming().getPageSizeField())) {
docLines.add("The maximum number of resources contained in the underlying API", "response. The API may return fewer values in a page, even if", "there are additional values to be retrieved.");
} else if (methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField())) {
docLines.add("A page token is used to specify a page of values to be returned.", "If no page token is specified (the default), the first page", "of values will be returned. Any page token used here must have", "been generated by a previous call to the API.");
} else {
docLines.addAll(context.getNamer().getDocLines(field));
}
if (field.isEnum()) {
// For enums, we alter the param type to int, and document where to find the relevant
// const values
String typeNameSingular = context.getTypeTable().getFullNameFor(field.getType().makeOptional());
if (field.isRepeated()) {
paramDoc.typeName("int[]");
} else {
paramDoc.typeName("int");
}
docLines.add("For allowed values, use constants defined on {@see " + typeNameSingular + "}");
}
paramDoc.lines(docLines.build());
paramDocs.add(paramDoc.build());
}
return paramDocs.build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.
private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
List<RestInterfaceConfigView> configViews = new ArrayList<>();
GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
SurfaceNamer namer = context.getNamer();
Map<String, List<HttpRule>> interfaces = new TreeMap<>();
Service serviceConfig = serviceModel.getServiceConfig();
for (MethodModel methodModel : context.getSupportedMethods()) {
GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
MethodConfig methodConfig = methodContext.getMethodConfig();
Method method = methodContext.getMethod();
// REST does not support streaming methods
if (methodConfig.isGrpcStreaming()) {
continue;
}
String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
String selector = httpRule.getSelector();
String interfaceName = selector.substring(0, selector.lastIndexOf("."));
addHttpRuleToMap(interfaces, interfaceName, httpRule);
}
for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
}
return configViews;
}
Aggregations