public override CsharpMethod PatchMethod(CsharpMethod method)
        {
            var part = method.Parts.First(p => p.Name == "name");

            part.ClrTypeNameOverride = "Names";
            return(method);
        }
Exemplo n.º 2
0
        public override CsharpMethod PatchMethod(CsharpMethod method)
        {
            var part = method.Parts.First(p => p.Name == "index");

            part.Required = true;
            return(method);
        }
        public override CsharpMethod PatchMethod(CsharpMethod method)
        {
            var requestParam = method.Url.Params.First(p => p.Key == "requests_per_second");

            //Handle float.PositiveInfinity as though "unlimited"
            requestParam.Value.Generator = (fieldType, mm, original, setter) =>
                                           $"public {fieldType} {mm} {{ " +
                                           $"get {{ var q = Q<string>(\"{original}\"); return (q == \"unlimited\")? float.PositiveInfinity : float.Parse(q); }} " +
                                           $"set {{ Q(\"{original}\", value == float.PositiveInfinity ? \"unlimited\" : value.ToString()); }} " +
                                           $"}}";

            requestParam.Value.FluentGenerator = (queryStringParamName, mm, original, setter) =>
                                                 $"public {queryStringParamName} {mm.ToPascalCase()}({requestParam.Value.CsharpType(mm)} {mm}) => " +
                                                 $"this.AddQueryString(\"{original}\", {setter} == float.PositiveInfinity ? \"unlimited\" : {setter}.ToString());";

            return(base.PatchMethod(method));
        }
Exemplo n.º 4
0
        //Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
        //or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings
        public void PatchMethod(CsharpMethod method)
        {
            Func <string, bool> ms = s => method.FullName.StartsWith(s);
            Func <string, bool> pc = s => method.Path.Contains(s);

            if (ms("Indices") && !pc("{index}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            if (ms("Nodes") && !pc("{node_id}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            //remove duplicate occurance of the HTTP method name
            var m = method.HttpMethod.ToPascalCase();

            method.FullName =
                Regex.Replace(method.FullName, m, a => a.Index != method.FullName.IndexOf(m, StringComparison.Ordinal) ? "" : m);

            foreach (var param in GlobalQueryParameters.Parameters)
            {
                if (!method.Url.Params.ContainsKey(param.Key))
                {
                    method.Url.Params.Add(param.Key, param.Value);
                }
            }

            string manualOverride;
            var    key = method.QueryStringParamName.Replace("RequestParameters", "");

            if (MethodNameOverrides.TryGetValue(key, out manualOverride))
            {
                method.QueryStringParamName = manualOverride + "RequestParameters";
            }

            method.DescriptorType = method.QueryStringParamName.Replace("RequestParameters", "Descriptor");
            method.RequestType    = method.QueryStringParamName.Replace("RequestParameters", "Request");
            string requestGeneric;

            if (KnownRequests.TryGetValue("I" + method.RequestType, out requestGeneric))
            {
                method.RequestTypeGeneric = requestGeneric;
            }
            else
            {
                method.RequestTypeUnmapped = true;
            }

            method.Allow404 = ApiEndpointsThatAllow404.Endpoints.Contains(method.DescriptorType.Replace("Descriptor", ""));

            string generic;

            if (KnownDescriptors.TryGetValue(method.DescriptorType, out generic))
            {
                method.DescriptorTypeGeneric = generic;
            }
            else
            {
                method.Unmapped = true;
            }

            try
            {
                IEnumerable <string>         skipList   = new List <string>();
                IDictionary <string, string> renameList = new Dictionary <string, string>();

                var typeName = "CodeGeneration.LowLevelClient.Overrides.Descriptors." + method.DescriptorType + "Overrides";
                var type     = Assembly.GetType(typeName);
                if (type != null)
                {
                    var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
                    if (overrides != null)
                    {
                        skipList   = overrides.SkipQueryStringParams ?? skipList;
                        renameList = overrides.RenameQueryStringParams ?? renameList;
                    }
                }

                var globalQueryStringRenames = new Dictionary <string, string>
                {
                    { "_source", "source_enabled" },
                    { "_source_include", "source_include" },
                    { "_source_exclude", "source_exclude" },
                    { "q", "query_on_query_string" },
                };

                foreach (var kv in globalQueryStringRenames)
                {
                    if (!renameList.ContainsKey(kv.Key))
                    {
                        renameList[kv.Key] = kv.Value;
                    }
                }

                var patchedParams = new Dictionary <string, ApiQueryParameters>();
                foreach (var kv in method.Url.Params)
                {
                    if (kv.Value.OriginalQueryStringParamName.IsNullOrEmpty())
                    {
                        kv.Value.OriginalQueryStringParamName = kv.Key;
                    }
                    if (skipList.Contains(kv.Key))
                    {
                        continue;
                    }

                    string newName;
                    if (!renameList.TryGetValue(kv.Key, out newName))
                    {
                        patchedParams.Add(kv.Key, kv.Value);
                        continue;
                    }

                    patchedParams.Add(newName, kv.Value);

                    //if (newName == "source_enabled")
                    //{
                    //	kv.Value.DeprecatedInFavorOf = "EnableSource";
                    //	patchedParams.Add("enable_source", new ApiQueryParameters
                    //	{
                    //		Description = kv.Value.Description,
                    //		Options = kv.Value.Options,
                    //		Type = "boolean",
                    //		OriginalQueryStringParamName = "_source"
                    //	});
                    //}
                }

                method.Url.Params = patchedParams;
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }
Exemplo n.º 5
0
 public virtual CsharpMethod PatchMethod(CsharpMethod method)
 {
     return(method);
 }
 public virtual CsharpMethod PatchMethod(CsharpMethod method) => method;
Exemplo n.º 7
0
 public override CsharpMethod PatchMethod(CsharpMethod method)
 {
     method.Url.Params["reset_start"].Type = "date";
     method.Url.Params["reset_end"].Type   = "date";
     return(method);
 }
Exemplo n.º 8
0
        //Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
        //or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings
        public static void PatchMethod(CsharpMethod method)
        {
            Func <string, bool> ms = (s) => method.FullName.StartsWith(s);
            Func <string, bool> mc = (s) => method.FullName.Contains(s);
            Func <string, bool> pc = (s) => method.Path.Contains(s);

            if (ms("Indices") && !pc("{index}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            if (ms("Nodes") && !pc("{node_id}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            //remove duplicate occurance of the HTTP method name
            var m = method.HttpMethod.ToPascalCase();

            method.FullName =
                Regex.Replace(method.FullName, m, (a) => a.Index != method.FullName.IndexOf(m) ? "" : m);

            string manualOverride;
            var    key = method.QueryStringParamName.Replace("RequestParameters", "");

            if (MethodNameOverrides.TryGetValue(key, out manualOverride))
            {
                method.QueryStringParamName = manualOverride + "RequestParameters";
            }

            method.DescriptorType = method.QueryStringParamName.Replace("RequestParameters", "Descriptor");

            method.Allow404 = ApiEndpointsThatAllow404.Endpoints.Contains(method.DescriptorType.Replace("Descriptor", ""));

            string generic;

            if (KnownDescriptors.TryGetValue(method.DescriptorType, out generic))
            {
                method.DescriptorTypeGeneric = generic;
            }

            try
            {
                var typeName = "CodeGeneration.LowLevelClient.Overrides.Descriptors." + method.DescriptorType + "Overrides";
                var type     = _assembly.GetType(typeName);
                if (type == null)
                {
                    return;
                }
                var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
                if (overrides == null)
                {
                    return;
                }
                method.Url.Params = method.Url.Params.Where(p => !overrides.SkipQueryStringParams.Contains(p.Key))
                                    .ToDictionary(k => k.Key, v => v.Value);
            }
// ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }
Exemplo n.º 9
0
        //Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
        //or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings
        public static void PatchMethod(CsharpMethod method)
        {
            Func <string, bool> ms = (s) => method.FullName.StartsWith(s);
            Func <string, bool> mc = (s) => method.FullName.Contains(s);
            Func <string, bool> pc = (s) => method.Path.Contains(s);

            //if (ms("IndicesStats") && pc("{index}"))
            //method.FullName = method.FullName.Replace("IndicesStats", "IndexStats");
            //IndicesPutAliasPutAsync
            //if (ms("IndicesPutAlias") && pc("{index}"))
            //method.FullName = method.FullName.Replace("IndicesPutAlias", "IndexPutAlias");

            if (ms("IndicesStats") || ms("IndexStats"))
            {
                if (pc("/indexing/"))
                {
                    method.FullName = method.FullName.Replace("Stats", "IndexingStats");
                }
                if (pc("/search/"))
                {
                    method.FullName = method.FullName.Replace("Stats", "SearchStats");
                }
                if (pc("/fielddata/"))
                {
                    method.FullName = method.FullName.Replace("Stats", "FieldDataStats");
                }
            }

            if (ms("Indices") && !pc("{index}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            if (ms("Nodes") && !pc("{node_id}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            //if (ms("IndicesGetSettings") && !pc("{index}") && pc("{"))
            //	method.FullName = method.FullName.Replace("IndicesGetSettings", "IndicesSettings");

            //if (ms("IndicesGetMapping") && !pc("{index}") && pc("{"))
            //	method.FullName = method.FullName.Replace("IndicesGetMapping", "IndicesGetGlobalSettings");

            //remove duplicate occurance of the HTTP method name
            var m = method.HttpMethod.ToPascalCase();

            method.FullName =
                Regex.Replace(method.FullName, m, (a) => a.Index != method.FullName.IndexOf(m) ? "" : m);

            string manualOverride;
            var    key = method.QueryStringParamName.Replace("QueryString", "");

            if (MethodNameOverrides.TryGetValue(key, out manualOverride))
            {
                method.QueryStringParamName = manualOverride + "QueryString";
            }

            method.DescriptorType = method.QueryStringParamName.Replace("QueryString", "Descriptor");

            string generic;

            if (KnownDescriptors.TryGetValue(method.DescriptorType, out generic))
            {
                method.DescriptorTypeGeneric = generic;
            }

            try
            {
                var typeName = "CodeGeneration.LowLevelClient.Overrides.Descriptors." + method.DescriptorType + "Overrides";
                var type     = _assembly.GetType(typeName);
                if (type == null)
                {
                    return;
                }
                var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
                if (overrides == null)
                {
                    return;
                }
                method.Url.Params = method.Url.Params.Where(p => !overrides.SkipQueryStringParams.Contains(p.Key))
                                    .ToDictionary(k => k.Key, v => v.Value);
            }
// ReSharper disable once EmptyGeneralCatchClause
            catch (Exception e)
            {
            }
        }
Exemplo n.º 10
0
        //Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
        //or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings
        public static void PatchMethod(CsharpMethod method)
        {
            Func <string, bool> ms = (s) => method.FullName.StartsWith(s);
            Func <string, bool> mc = (s) => method.FullName.Contains(s);
            Func <string, bool> pc = (s) => method.Path.Contains(s);

            if (ms("Indices") && !pc("{index}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            if (ms("Nodes") && !pc("{node_id}"))
            {
                method.FullName = (method.FullName + "ForAll").Replace("AsyncForAll", "ForAllAsync");
            }

            //remove duplicate occurance of the HTTP method name
            var m = method.HttpMethod.ToPascalCase();

            method.FullName =
                Regex.Replace(method.FullName, m, (a) => a.Index != method.FullName.IndexOf(m) ? "" : m);

            string manualOverride;
            var    key = method.QueryStringParamName.Replace("RequestParameters", "");

            if (MethodNameOverrides.TryGetValue(key, out manualOverride))
            {
                method.QueryStringParamName = manualOverride + "RequestParameters";
            }

            method.DescriptorType = method.QueryStringParamName.Replace("RequestParameters", "Descriptor");
            method.RequestType    = method.QueryStringParamName.Replace("RequestParameters", "Request");
            string requestGeneric;

            if (KnownRequests.TryGetValue("I" + method.RequestType, out requestGeneric))
            {
                method.RequestTypeGeneric = requestGeneric;
            }
            else
            {
                method.RequestTypeUnmapped = true;
            }

            method.Allow404 = ApiEndpointsThatAllow404.Endpoints.Contains(method.DescriptorType.Replace("Descriptor", ""));

            string generic;

            if (KnownDescriptors.TryGetValue(method.DescriptorType, out generic))
            {
                method.DescriptorTypeGeneric = generic;
            }
            else
            {
                method.Unmapped = true;
            }

            try
            {
                IEnumerable <string>         skipList   = new List <string>();
                IDictionary <string, string> renameList = new Dictionary <string, string>();

                var typeName = "CodeGeneration.LowLevelClient.Overrides.Descriptors." + method.DescriptorType + "Overrides";
                var type     = _assembly.GetType(typeName);
                if (type != null)
                {
                    var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
                    if (overrides != null)
                    {
                        skipList   = overrides.SkipQueryStringParams ?? skipList;
                        renameList = overrides.RenameQueryStringParams ?? renameList;
                    }
                }


                var globalQueryStringRenames = new Dictionary <string, string>
                {
                    { "_source", "source_enabled" },
                    { "_source_include", "source_include" },
                    { "_source_exclude", "source_exclude" },
                };

                foreach (var kv in globalQueryStringRenames)
                {
                    if (!renameList.ContainsKey(kv.Key))
                    {
                        renameList[kv.Key] = kv.Value;
                    }
                }

                foreach (var kv in method.Url.Params)
                {
                    if (skipList.Contains(kv.Key))
                    {
                        method.Url.Params.Remove(kv.Key);
                        continue;
                    }

                    string newName;
                    if (!renameList.TryGetValue(kv.Key, out newName))
                    {
                        continue;
                    }

                    method.Url.Params.Remove(kv.Key);
                    method.Url.Params.Add(newName, kv.Value);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }