use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class NodeJSSurfaceNamer method returnCallbackDocLines.
private List<String> returnCallbackDocLines(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
String returnTypeDoc = returnTypeDoc(typeTable, methodConfig);
Method method = methodConfig.getMethod();
MethodModel methodModel = methodConfig.getMethodModel();
String classInfo = getParamTypeName(typeTable, methodModel.getOutputType());
String callbackType;
if (isProtobufEmpty(method.getOutputMessage())) {
callbackType = "function(?Error)";
} else if (methodConfig.isPageStreaming()) {
callbackType = String.format("function(?Error, ?Array, ?Object, ?%s)", classInfo);
} else {
callbackType = String.format("function(?Error, ?%s)", classInfo);
}
ImmutableList.Builder<String> callbackLines = ImmutableList.builder();
callbackLines.add("@param {" + callbackType + "} [callback]", " The function which will be called with the result of the API call.");
if (!isProtobufEmpty(method.getOutputMessage())) {
callbackLines.add("", " The second parameter to the callback is " + returnTypeDoc + ".");
if (methodConfig.isPageStreaming()) {
callbackLines.add("", " When autoPaginate: false is specified through options, it contains the result", " in a single response. If the response indicates the next page exists, the third", " parameter is set to be used for the next request object. The fourth parameter keeps", " the raw response object of " + getTypeNameDoc(typeTable, methodModel.getOutputType()) + ".");
}
}
return callbackLines.build();
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class PhpGapicSurfaceTestTransformer 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);
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
InitCodeOutputType initCodeOutputType = InitCodeOutputType.FieldList;
if (methodContext.getMethodConfig().getGrpcStreamingType() == GrpcStreamingType.BidiStreaming) {
initCodeOutputType = InitCodeOutputType.SingleObject;
}
ClientMethodType clientMethodType = ClientMethodType.OptionalArrayMethod;
if (methodContext.getMethodConfig().isLongRunningOperation()) {
clientMethodType = ClientMethodType.OperationOptionalArrayMethod;
} else if (methodContext.getMethodConfig().isPageStreaming()) {
clientMethodType = ClientMethodType.PagedOptionalArrayMethod;
}
Iterable<FieldConfig> fieldConfigs = methodContext.getMethodConfig().getRequiredFieldConfigs();
InitCodeContext initCodeContext = InitCodeContext.newBuilder().initObjectType(methodContext.getMethodModel().getInputType()).suggestedName(Name.from("request")).initFieldConfigStrings(methodContext.getMethodConfig().getSampleCodeInitFields()).initValueConfigMap(InitCodeTransformer.createCollectionMap(methodContext)).initFields(FieldConfig.toFieldTypeIterable(fieldConfigs)).outputType(initCodeOutputType).fieldConfigMap(FieldConfig.toFieldConfigMap(fieldConfigs)).valueGenerator(valueGenerator).build();
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType));
}
return testCaseViews;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class MethodTransformer method generateMethods.
public List<MethodView> generateMethods(InterfaceModel apiInterface, Map<String, String> collectionNameMap) {
ImmutableList.Builder<MethodView> methods = ImmutableList.builder();
for (MethodModel method : apiInterface.getMethods()) {
MethodView.Builder methodView = MethodView.newBuilder();
methodView.name(method.getRawName());
generateField(method, methodView);
generatePageStreaming(method, methodView);
generateRetry(method, methodView);
generateFieldNamePatterns(method, methodView, collectionNameMap);
methodView.timeoutMillis("60000");
methods.add(methodView.build());
}
return methods.build();
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class JavaDiscoGapicRequestToViewTransformer method transform.
@Override
public List<ViewModel> transform(DiscoApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceRequests = new ArrayList<>();
String packageName = productConfig.getPackageName();
SurfaceNamer surfaceNamer = new JavaSurfaceNamer(packageName, packageName, nameFormatter);
for (InterfaceModel apiInterface : model.getInterfaces()) {
boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
DiscoGapicInterfaceContext context = JavaDiscoGapicSurfaceTransformer.newInterfaceContext(apiInterface, productConfig, surfaceNamer, createTypeTable(productConfig.getPackageName()), enableStringFormatFunctions);
for (MethodModel method : context.getSupportedMethods()) {
RequestObjectParamView params = getRequestObjectParams(context, method);
SchemaTransformationContext requestContext = SchemaTransformationContext.create(method.getFullName(), context.getSchemaTypeTable(), context);
StaticLangApiMessageView requestView = generateRequestClass(requestContext, method, params);
surfaceRequests.add(generateRequestFile(requestContext, requestView));
}
}
Collections.sort(surfaceRequests, new Comparator<ViewModel>() {
@Override
public int compare(ViewModel o1, ViewModel o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.outputPath(), o2.outputPath());
}
});
return surfaceRequests;
}
use of com.google.api.codegen.config.MethodModel in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method createLongRunningDescriptors.
private List<LongRunningOperationDetailView> createLongRunningDescriptors(GapicInterfaceContext context) {
List<LongRunningOperationDetailView> result = new ArrayList<>();
for (MethodModel method : context.getLongRunningMethods()) {
GapicMethodContext methodContext = context.asDynamicMethodContext(method);
LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig();
TypeModel returnType = lroConfig.getReturnType();
TypeModel metadataType = lroConfig.getMetadataType();
result.add(LongRunningOperationDetailView.newBuilder().methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).transportMethodName(context.getNamer().getGrpcMethodName(method)).constructorName("").clientReturnTypeName("").operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)).isEmptyOperation(lroConfig.getReturnType().isEmptyType()).metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)).implementsCancel(true).implementsDelete(true).initialPollDelay(lroConfig.getInitialPollDelay().toMillis()).pollDelayMultiplier(lroConfig.getPollDelayMultiplier()).maxPollDelay(lroConfig.getMaxPollDelay().toMillis()).totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()).build());
}
return result;
}
Aggregations