Search in sources :

Example 1 with DiscoGapicInterfaceConfig

use of com.google.api.codegen.config.DiscoGapicInterfaceConfig in project toolkit by googleapis.

the class ApiCallableTransformer method generateHttpFields.

private HttpMethodView generateHttpFields(MethodContext context) {
    if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.HTTP)) {
        Method method = ((DiscoveryMethodModel) context.getMethodModel()).getDiscoMethod();
        HttpMethodView.Builder httpMethodView = HttpMethodView.newBuilder();
        httpMethodView.fullMethodName(method.id());
        httpMethodView.httpMethod(method.httpMethod());
        List<String> pathParams = new ArrayList<>(method.pathParams().keySet());
        List<String> queryParams = new ArrayList<>(method.queryParams().keySet());
        Collections.sort(pathParams);
        Collections.sort(queryParams);
        httpMethodView.pathParams(pathParams);
        httpMethodView.queryParams(queryParams);
        httpMethodView.pathTemplate(method.path());
        // TODO(andrealin): handle multiple resource names.
        DiscoGapicInterfaceConfig interfaceConfig = (DiscoGapicInterfaceConfig) context.getSurfaceInterfaceContext().getInterfaceConfig();
        SingleResourceNameConfig nameConfig = interfaceConfig.methodToResourceNameMap().get(context.getMethodConfig());
        httpMethodView.resourceNameTypeName(context.getNamer().publicClassName(DiscoGapicParser.getResourceNameName(nameConfig)));
        // Find the field with the resource name config.
        for (FieldConfig fieldConfig : context.getMethodConfig().getRequiredFieldConfigs()) {
            if (fieldConfig.getResourceNameConfig() != null && fieldConfig.getResourceNameConfig().equals(nameConfig)) {
                httpMethodView.resourceNameFieldName(context.getNamer().privateFieldName(Name.anyCamel(fieldConfig.getField().getNameAsParameter())));
            }
        }
        return httpMethodView.build();
    } else {
        return null;
    }
}
Also used : FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) HttpMethodView(com.google.api.codegen.viewmodel.HttpMethodView) DiscoGapicInterfaceConfig(com.google.api.codegen.config.DiscoGapicInterfaceConfig) Method(com.google.api.codegen.discovery.Method) DiscoveryMethodModel(com.google.api.codegen.config.DiscoveryMethodModel) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Aggregations

DiscoGapicInterfaceConfig (com.google.api.codegen.config.DiscoGapicInterfaceConfig)1 DiscoveryMethodModel (com.google.api.codegen.config.DiscoveryMethodModel)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 Method (com.google.api.codegen.discovery.Method)1 HttpMethodView (com.google.api.codegen.viewmodel.HttpMethodView)1 ArrayList (java.util.ArrayList)1