public static CsharpMethod Clone(CsharpMethod method)
		{
			return new CsharpMethod
			{
				Allow404 = method.Allow404,
				Path = method.Path,
				RequestType = method.RequestType,
				ReturnDescription = method.ReturnDescription,
				Arguments = method.Arguments,
				CallTypeGeneric = method.CallTypeGeneric,
				DescriptorType = method.DescriptorType,
				DescriptorTypeGeneric = method.DescriptorTypeGeneric,
				Documentation = method.Documentation,
				FullName = method.FullName,
				HttpMethod = method.HttpMethod,
				Parts = method.Parts,
				QueryStringParamName = method.QueryStringParamName,
				RequestTypeGeneric = method.RequestTypeGeneric,
				RequestTypeUnmapped = method.RequestTypeUnmapped,
				ReturnType = method.ReturnType,
				ReturnTypeGeneric = method.ReturnTypeGeneric,
				Unmapped = method.Unmapped,
				Url = method.Url,
				SkipInterface = method.SkipInterface
			};
		}
 public static CsharpMethod Clone(CsharpMethod method)
 {
     return(new CsharpMethod
     {
         Allow404 = method.Allow404,
         Path = method.Path,
         RequestType = method.RequestType,
         ReturnDescription = method.ReturnDescription,
         Arguments = method.Arguments,
         CallTypeGeneric = method.CallTypeGeneric,
         DescriptorType = method.DescriptorType,
         DescriptorTypeGeneric = method.DescriptorTypeGeneric,
         Documentation = method.Documentation,
         FullName = method.FullName,
         HttpMethod = method.HttpMethod,
         Parts = method.Parts,
         QueryStringParamName = method.QueryStringParamName,
         RequestTypeGeneric = method.RequestTypeGeneric,
         RequestTypeUnmapped = method.RequestTypeUnmapped,
         ReturnType = method.ReturnType,
         ReturnTypeGeneric = method.ReturnTypeGeneric,
         Unmapped = method.Unmapped,
         Url = method.Url,
         SkipInterface = method.SkipInterface
     });
 }
		//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
			{
			}

		}
Exemple #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 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("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)
            {
            }
        }
Exemple #5
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> 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 (CodeConfiguration.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 (CodeConfiguration.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 (CodeConfiguration.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     = CodeConfiguration.Assembly.GetType(typeName);
                if (type != null)
                {
                    var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
                    if (overrides != null)
                    {
                        skipList   = overrides.SkipQueryStringParams ?? skipList;
                        renameList = overrides.RenameQueryStringParams ?? renameList;

                        overrides.PatchMethod(method);
                    }
                }

                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);
                }

                method.Url.Params = patchedParams;
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }
		public override CsharpMethod PatchMethod(CsharpMethod method)
		{
			var part = method.Parts.First(p => p.Name == "name");
			part.ClrTypeNameOverride = "Names";
			return method;
		}
Exemple #7
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
			{
			}

		}
		public override CsharpMethod PatchMethod(CsharpMethod method)
		{
			var part = method.Parts.First(p => p.Name == "index");
			part.Required = true;
			return method;
		}
		public virtual CsharpMethod PatchMethod(CsharpMethod method)
		{
			return method;
		}