use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
MethodContext methodContext = context.asRequestMethodContext(method);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
} else if (methodConfig.isFlattening()) {
ClientMethodType clientMethodType;
if (methodConfig.isPageStreaming()) {
clientMethodType = ClientMethodType.PagedFlattenedMethod;
} else if (methodConfig.isLongRunningOperation()) {
clientMethodType = ClientMethodType.AsyncOperationFlattenedMethod;
} else {
clientMethodType = ClientMethodType.FlattenedMethod;
}
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
} else {
// TODO: Add support of non-flattening method
// Github issue: https://github.com/googleapis/toolkit/issues/393
System.err.println("Non-flattening method test is not supported yet for " + method.getSimpleName());
}
}
return testCaseViews;
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class NodeJSApiMethodParamTransformer method generateRequestObjectParamDoc.
private ParamDocView generateRequestObjectParamDoc(GapicMethodContext context) {
MethodConfig methodConfig = context.getMethodConfig();
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
paramDoc.lines(ImmutableList.of("The request object that will be sent."));
String paramName = context.getNamer().localVarName(Name.from("request"));
Iterable<FieldModel> optionalParams = removePageTokenFromFields(methodConfig);
if (!methodConfig.getRequiredFieldConfigs().iterator().hasNext() && !optionalParams.iterator().hasNext()) {
paramName = String.format("[%s]", paramName);
}
paramDoc.paramName(paramName);
paramDoc.typeName("Object");
return paramDoc.build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class NodeJSApiMethodParamTransformer method generateMethodParamDocs.
private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields, boolean isOptional) {
SurfaceNamer namer = context.getNamer();
MethodConfig methodConfig = context.getMethodConfig();
ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
for (FieldModel field : fields) {
if (isRequestTokenParam(methodConfig, field)) {
continue;
}
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
String paramName = "request." + namer.getVariableName(field);
if (isOptional) {
paramName = String.format("[%s]", paramName);
}
paramDoc.paramName(paramName);
String typeName = namer.getParamTypeName(context.getTypeTable(), field.getType());
paramDoc.typeName(typeName);
List<String> fieldDocLines = namer.getDocLines(field);
ImmutableList.Builder<String> docLines = ImmutableList.builder();
if (isPageSizeParam(methodConfig, field)) {
docLines.add("The maximum number of resources contained in the underlying API", "response. If page streaming is performed per-resource, this", "parameter does not affect the return value. If page streaming is", "performed per-page, this determines the maximum number of", "resources in a page.");
} else {
docLines.addAll(fieldDocLines);
}
paramDoc.lines(docLines.build());
docs.add(paramDoc.build());
}
return docs.build();
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PhpSurfaceNamer method getDynamicLangReturnTypeName.
@Override
public String getDynamicLangReturnTypeName(MethodContext methodContext) {
MethodModel method = methodContext.getMethodModel();
MethodConfig methodConfig = methodContext.getMethodConfig();
if (method.isOutputTypeEmpty()) {
return "";
}
if (methodConfig.isPageStreaming()) {
return "\\Google\\ApiCore\\PagedListResponse";
}
if (methodConfig.isLongRunningOperation()) {
return "\\Google\\ApiCore\\OperationResponse";
}
switch(methodConfig.getGrpcStreamingType()) {
case NonStreaming:
return method.getOutputTypeName(methodContext.getTypeTable()).getFullName();
case BidiStreaming:
return "\\Google\\ApiCore\\BidiStream";
case ClientStreaming:
return "\\Google\\ApiCore\\ClientStream";
case ServerStreaming:
return "\\Google\\ApiCore\\ServerStream";
default:
return getNotImplementedString("SurfaceNamer.getDynamicReturnTypeName grpcStreamingType:" + methodConfig.getGrpcStreamingType().toString());
}
}
use of com.google.api.codegen.config.MethodConfig in project toolkit by googleapis.
the class PythonApiMethodParamTransformer method generateMethodParamDocs.
private List<ParamDocView> generateMethodParamDocs(GapicMethodContext context, Iterable<FieldModel> fields) {
SurfaceNamer namer = context.getNamer();
MethodConfig methodConfig = context.getMethodConfig();
ImmutableList.Builder<ParamDocView> docs = ImmutableList.builder();
for (FieldModel field : fields) {
if (isRequestTokenParam(methodConfig, field)) {
continue;
}
SimpleParamDocView.Builder paramDoc = SimpleParamDocView.newBuilder();
paramDoc.paramName(namer.getVariableName(field));
paramDoc.typeName(namer.getParamTypeName(context.getTypeTable(), field.getType()));
ImmutableList.Builder<String> docLines = ImmutableList.builder();
if (isPageSizeParam(methodConfig, field)) {
docLines.add("The maximum number of resources contained in the", "underlying API response. If page streaming is performed per-", "resource, this parameter does not affect the return value. If page", "streaming is performed per-page, this determines the maximum number", "of resources in a page.");
} else {
docLines.addAll(namer.getDocLines(field));
boolean isMessageField = field.isMessage() && !field.isMap();
boolean isMapContainingMessage = field.isMap() && field.getMapValueField().isMessage();
if (isMessageField || isMapContainingMessage) {
String messageType;
if (isMapContainingMessage) {
messageType = context.getTypeTable().getFullNameForElementType(field.getMapValueField());
} else {
messageType = context.getTypeTable().getFullNameForElementType(field);
}
docLines.add("If a dict is provided, it must be of the same form as the protobuf", String.format("message :class:`%s`", PythonDocstringUtil.napoleonType(messageType, namer.getVersionedDirectoryNamespace())));
}
}
paramDoc.lines(docLines.build());
docs.add(paramDoc.build());
}
return docs.build();
}
Aggregations