Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/CodeGeneration/CodeGeneration.LowLevelClient/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,25 @@ public static void PatchMethod(CsharpMethod method)
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);

foreach (var kv in method.Url.Params)
{
if (overrides.SkipQueryStringParams.Contains(kv.Key))
method.Url.Params.Remove(kv.Key);

if (overrides.RenameQueryStringParams == null) continue;

string newName;
if (!overrides.RenameQueryStringParams.TryGetValue(kv.Key, out newName))
continue;

method.Url.Params.Remove(kv.Key);
method.Url.Params.Add(newName, kv.Value);

}

//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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<Compile Include="Domain\CsharpMethod.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Overrides\Allow404\ApiEndpointsThatAllow404.cs" />
<Compile Include="Overrides\Descriptors\IDescriptorOverrides.cs" />
<Compile Include="Overrides\Descriptors\NodesHotThreadsDescriptorOverrides.cs" />
<Compile Include="Overrides\Descriptors\DeleteWarmerDescriptorOverrides.cs" />
<Compile Include="Overrides\Descriptors\PutTemplateDescriptorOverrides.cs" />
<Compile Include="Overrides\Descriptors\ClearCacheDescriptorOverrides.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public IEnumerable<CsharpMethod> CsharpMethods
case "list":
return "string " + p.Name;
case "enum":
return this.PascalCase(p.Name) + "Options " + p.Name;
return this.PascalCase(p.Name) + p.Name;
default:
return p.Type + " " + p.Name;
//return "string " + p.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public string CsharpType(string paramName)
case null:
return "string";
case "enum":
return paramName.ToPascalCase() + "Options";
return paramName.ToPascalCase();
default:
return this.Type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IEnumerable<EnumDescription> EnumsInTheSpec
get
{
var queryParamEnums = from m in this.CsharpMethodsWithQueryStringInfo.SelectMany(m => m.Url.Params)
where m.Value.CsharpType(m.Key).EndsWith("Options")
where m.Value.Type == "enum"
select new EnumDescription
{
Name = m.Value.CsharpType(m.Key),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public IEnumerable<string> SkipQueryStringParams
};
}
}

public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public IEnumerable<string> SkipQueryStringParams
};
}
}

public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
{
/// <summary>
/// Tweaks the generated descriptors
/// </summary>
public interface IDescriptorOverrides
{
/// <summary>
/// Sometimes params can be defined on the body as well as on the querystring
/// We favor specifying params on the body so here we can specify params we don't want on the querystring.
/// </summary>
IEnumerable<string> SkipQueryStringParams { get; }

/// <summary>
/// Override how the query param name is exposed to the client.
/// </summary>
IDictionary<string, string> RenameQueryStringParams { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public IEnumerable<string> SkipQueryStringParams
};
}
}
public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
{
public class NodesHotThreadsDescriptorOverrides : IDescriptorOverrides
{
public IEnumerable<string> SkipQueryStringParams
{
get
{
return new string[]
{
"fielddata"
};
}
}
public IDictionary<string, string> RenameQueryStringParams
{
get
{
return new Dictionary<string, string>
{
{ "type", "thread_type"}
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public IEnumerable<string> SkipQueryStringParams
};
}
}
public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@

namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
{
/// <summary>
/// Tweaks the generated descriptors
/// </summary>
public interface IDescriptorOverrides
{
/// <summary>
/// Sometimes params can be defined on the body as well as on the querystring
/// We favor specifying params on the body so here we can specify params we don't want on the querystring.
/// </summary>
IEnumerable<string> SkipQueryStringParams { get; }
}


public class SearchDescriptorOverrides : IDescriptorOverrides
{
public IEnumerable<string> SkipQueryStringParams
Expand All @@ -40,5 +27,7 @@ public IEnumerable<string> SkipQueryStringParams
};
}
}

public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
}
}
4 changes: 2 additions & 2 deletions src/Elasticsearch.Net/Connection/ConnectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace Elasticsearch.Net.Connection
/// </summary>
public class ConnectionConfiguration :
ConnectionConfiguration<ConnectionConfiguration>,
IConnectionConfiguration<ConnectionConfiguration>,
IHideObjectMembers
IConnectionConfiguration<ConnectionConfiguration>
{
/// <summary>
/// ConnectionConfiguration allows you to control how ElasticsearchClient behaves and where/how it connects
Expand Down Expand Up @@ -293,6 +292,7 @@ public T SetConnectionStatusHandler(Action<IElasticsearchResponse> handler)
this._connectionStatusHandler = handler;
return (T)this;
}

}
}

3 changes: 1 addition & 2 deletions src/Elasticsearch.Net/Connection/IConnectionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
namespace Elasticsearch.Net.Connection
{
public interface IConnectionConfiguration :
IConnectionConfiguration<IConnectionConfiguration>,
IHideObjectMembers
IConnectionConfiguration<IConnectionConfiguration>
{

}
Expand Down
Loading