use of com.google.api.codegen.viewmodel.RestInterfaceConfigView 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