use of com.google.api.HttpRule in project toolkit by googleapis.
the class PhpGapicSurfaceTransformer method generateRestMethodConfigView.
private RestMethodConfigView generateRestMethodConfigView(HttpRule httpRule, SurfaceNamer namer) {
String body = httpRule.getBody();
String selector = httpRule.getSelector();
List<String> additionalBindings = new ArrayList<>();
Map.Entry<String, String> entry = getHttpMethodEntry(httpRule);
String uriTemplate = entry.getValue();
Set<String> templateVars = PathTemplate.create(uriTemplate).vars();
if (httpRule.getAdditionalBindingsCount() > 0) {
for (HttpRule additionalBindingHttpRule : httpRule.getAdditionalBindingsList()) {
additionalBindings.add(getHttpMethodEntry(additionalBindingHttpRule).getValue());
}
}
return RestMethodConfigView.newBuilder().additionalBindings(additionalBindings).hasAdditionalBindings(additionalBindings.size() > 0).placeholders(generateRestPlaceholderConfigViews(namer, templateVars)).hasPlaceholders(templateVars.size() > 0).method(entry.getKey()).uriTemplate(uriTemplate).name(selector.substring(selector.lastIndexOf(".") + 1)).hasBody(!body.isEmpty()).body(body).build();
}
use of com.google.api.HttpRule 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