use of com.google.api.tools.framework.model.Method 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.tools.framework.model.Method in project toolkit by googleapis.
the class ProtoInterfaceModel method getMethods.
@Override
public List<MethodModel> getMethods() {
ImmutableList.Builder<MethodModel> methods = ImmutableList.builder();
for (Method method : protoInterface.getMethods()) {
methods.add(new ProtoMethodModel(method));
}
SymbolTable symbolTable = protoInterface.getModel().getSymbolTable();
for (Mixin mixin : protoInterface.getConfig().getMixinsList()) {
Interface mixinInterface = symbolTable.lookupInterface(mixin.getName());
for (Method method : mixinInterface.getMethods()) {
methods.add(new ProtoMethodModel(method));
}
}
return methods.build();
}
use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class ProtoInterfaceTransformer method getResourceToEntityNameMap.
@Override
public Map<String, String> getResourceToEntityNameMap(InterfaceModel apiInterface) {
Interface protoInterface = ((ProtoInterfaceModel) apiInterface).getInterface();
// Using a map with the string representation of the resource path to avoid duplication
// of equivalent paths.
// Using a TreeMap in particular so that the ordering is deterministic
// (useful for testability).
Map<String, CollectionPattern> specs = new TreeMap<>();
for (Method method : protoInterface.getReachableMethods()) {
for (CollectionPattern collectionPattern : CollectionPattern.getCollectionPatternsFromMethod(method)) {
String resourcePath = collectionPattern.getTemplatizedResourcePath();
// If there are multiple field segments with the same resource path, the last
// one will be used, making the output deterministic. Also, the first field path
// encountered tends to be simply "name" because it is the corresponding create
// API method for the type.
specs.put(resourcePath, collectionPattern);
}
}
Set<String> usedNameSet = new HashSet<>();
ImmutableMap.Builder<String, String> nameMapBuilder = ImmutableMap.builder();
for (CollectionPattern collectionPattern : specs.values()) {
String resourceNameString = collectionPattern.getTemplatizedResourcePath();
String entityNameString = collectionPattern.getUniqueName(usedNameSet);
usedNameSet.add(entityNameString);
nameMapBuilder.put(resourceNameString, entityNameString);
}
return nameMapBuilder.build();
}
use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class GapicInterfaceConfig method createMethodConfigMap.
private static ImmutableMap<String, GapicMethodConfig> createMethodConfigMap(DiagCollector diagCollector, String language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ImmutableSet<String> retryCodesConfigNames, ImmutableSet<String> retryParamsConfigNames) {
ImmutableMap.Builder<String, GapicMethodConfig> methodConfigMapBuilder = ImmutableMap.builder();
for (MethodConfigProto methodConfigProto : interfaceConfigProto.getMethodsList()) {
Interface targetInterface = getTargetInterface(apiInterface, methodConfigProto.getRerouteToGrpcInterface());
Method method = targetInterface.lookupMethod(methodConfigProto.getName());
if (method == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "method not found: %s", methodConfigProto.getName()));
continue;
}
GapicMethodConfig methodConfig = GapicMethodConfig.createMethodConfig(diagCollector, language, methodConfigProto, method, messageConfigs, resourceNameConfigs, retryCodesConfigNames, retryParamsConfigNames);
if (methodConfig == null) {
continue;
}
methodConfigMapBuilder.put(methodConfigProto.getName(), methodConfig);
}
if (diagCollector.getErrorCount() > 0) {
return null;
} else {
return methodConfigMapBuilder.build();
}
}
Aggregations