use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class GapicContext method getSupportedMethodsV2.
/**
* Returns a list of RPC methods supported by the context, taking into account GRPC interface
* rerouting. TODO replace getSupportedMethods with this when all languages are migrated.
*/
public List<Method> getSupportedMethodsV2(Interface apiInterface) {
GapicInterfaceConfig interfaceConfig = getApiConfig().getInterfaceConfig(apiInterface);
if (interfaceConfig == null) {
throw new IllegalStateException("Service not configured in GAPIC config: " + apiInterface.getFullName());
}
List<Method> methods = new ArrayList<>(interfaceConfig.getMethodConfigs().size());
for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) {
Method method = ((GapicMethodConfig) methodConfig).getMethod();
if (isSupported(method)) {
methods.add(method);
}
}
return methods;
}
use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class NodeJSSurfaceNamer method getReturnDocLines.
/**
* Return JSDoc callback comment and return type comment for the given method.
*/
@Override
public List<String> getReturnDocLines(TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) {
GapicMethodConfig methodConfig = (GapicMethodConfig) methodContext.getMethodConfig();
Method method = methodConfig.getMethod();
if (method.getRequestStreaming() && method.getResponseStreaming()) {
return bidiStreamingReturnDocLines(method);
} else if (method.getResponseStreaming()) {
return responseStreamingReturnDocLines(method);
}
List<String> callbackLines = returnCallbackDocLines(context.getImportTypeTable(), methodConfig);
List<String> returnObjectLines = returnObjectDocLines(context.getImportTypeTable(), methodConfig);
return ImmutableList.<String>builder().addAll(callbackLines).addAll(returnObjectLines).build();
}
use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class NodeJSSurfaceNamer method returnObjectDocLines.
private List<String> returnObjectDocLines(ImportTypeTable typeTable, GapicMethodConfig methodConfig) {
String returnTypeDoc = returnTypeDoc(typeTable, methodConfig);
Method method = methodConfig.getMethod();
ImmutableList.Builder<String> returnMessageLines = ImmutableList.builder();
if (method.getRequestStreaming()) {
returnMessageLines.add("@returns {Stream} - A writable stream which accepts objects representing", " " + commentReformatter.getLinkedElementName(method.getInputType().getMessageType()) + " for write() method.");
} else {
if (isProtobufEmpty(method.getOutputMessage())) {
returnMessageLines.add("@returns {Promise} - The promise which resolves when API call finishes.");
} else {
returnMessageLines.add("@returns {Promise} - The promise which resolves to an array.", " The first element of the array is " + returnTypeDoc + ".");
if (methodConfig.isPageStreaming()) {
returnMessageLines.add("", " When autoPaginate: false is specified through options, the array has three " + "elements.", " The first element is " + returnTypeDoc + " in a single response.", " The second element is the next request object if the response", " indicates the next page exists, or null. The third element is ", " " + getTypeNameDoc(typeTable, methodConfig.getMethodModel().getOutputType()) + ".", "");
}
}
returnMessageLines.add(" The promise has a method named \"cancel\" which cancels the ongoing API call.");
}
return returnMessageLines.build();
}
use of com.google.api.tools.framework.model.Method 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;
}
use of com.google.api.tools.framework.model.Method in project toolkit by googleapis.
the class HeaderRequestParamTransformer method generateHeaderRequestParams.
public List<HeaderRequestParamView> generateHeaderRequestParams(MethodContext context) {
if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableList.of();
}
GapicMethodConfig methodConfig = (GapicMethodConfig) context.getMethodConfig();
Method method = methodConfig.getMethod();
SurfaceNamer namer = context.getNamer();
if (method.getInputType() == null || !method.getInputType().isMessage()) {
return ImmutableList.of();
}
ImmutableList.Builder<HeaderRequestParamView> headerRequestParams = ImmutableList.builder();
MessageType inputMessageType = method.getInputType().getMessageType();
for (String headerRequestParam : methodConfig.getHeaderRequestParams()) {
headerRequestParams.add(generateHeaderRequestParam(headerRequestParam, inputMessageType, namer));
}
return headerRequestParams.build();
}
Aggregations