Search in sources :

Example 1 with HttpRule

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();
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule)

Example 2 with HttpRule

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;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

HttpRule (com.google.api.HttpRule)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Service (com.google.api.Service)1 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 RestInterfaceConfigView (com.google.api.codegen.viewmodel.RestInterfaceConfigView)1 Method (com.google.api.tools.framework.model.Method)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1