Skip to content

Commit a44fb49

Browse files
committed
Started on generating querystring params
1 parent 18e2814 commit a44fb49

File tree

9 files changed

+115
-25
lines changed

9 files changed

+115
-25
lines changed

src/Nest/ElasticClient-Aliases.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public IIndicesOperationResponse Alias(string index, string alias)
9696
/// </summary>
9797
public IIndicesOperationResponse Alias(string index, IEnumerable<string> aliases)
9898
{
99-
aliases.Select(a => _createCommand("add", new AliasParams { Index = index, Alias = a }));
100-
var q = string.Join(",", aliases);
99+
var cmds = aliases.Select(a => _createCommand("add", new AliasParams { Index = index, Alias = a }));
100+
var q = string.Join(",", cmds);
101101
return this._Alias(q);
102102
}
103103
/// <summary>
@@ -106,8 +106,8 @@ public IIndicesOperationResponse Alias(string index, IEnumerable<string> aliases
106106
public IIndicesOperationResponse Alias(IEnumerable<string> aliases)
107107
{
108108
var index = this._connectionSettings.DefaultIndex;
109-
aliases.Select(a => _createCommand("add", new AliasParams { Index = index, Alias = a }));
110-
var q = string.Join(",", aliases);
109+
var cmds = aliases.Select(a => _createCommand("add", new AliasParams { Index = index, Alias = a }));
110+
var q = string.Join(",", cmds);
111111
return this._Alias(q);
112112
}
113113
/// <summary>
@@ -133,26 +133,26 @@ public IIndicesOperationResponse RemoveAlias(string index, string alias)
133133
public IIndicesOperationResponse RemoveAlias(IEnumerable<string> aliases)
134134
{
135135
var index = this._connectionSettings.DefaultIndex;
136-
aliases.Select(a => _createCommand("remove", new AliasParams { Index = index, Alias = a }));
137-
var q = string.Join(",", aliases);
136+
var cmds = aliases.Select(a => _createCommand("remove", new AliasParams { Index = index, Alias = a }));
137+
var q = string.Join(",", cmds);
138138
return this._Alias(q);
139139
}
140140
/// <summary>
141141
/// Remove multiple alias for the specified index
142142
/// </summary>
143143
public IIndicesOperationResponse RemoveAlias(string index, IEnumerable<string> aliases)
144144
{
145-
aliases.Select(a => _createCommand("remove", new AliasParams { Index = index, Alias = a }));
146-
var q = string.Join(",", aliases);
145+
var cmds = aliases.Select(a => _createCommand("remove", new AliasParams { Index = index, Alias = a }));
146+
var q = string.Join(",", cmds);
147147
return this._Alias(q);
148148
}
149149
/// <summary>
150150
/// Associate multiple indices with one alias
151151
/// </summary>
152152
public IIndicesOperationResponse Alias(IEnumerable<string> indices, string alias)
153153
{
154-
indices.Select(i => _createCommand("add", new AliasParams { Index = i, Alias = alias }));
155-
var q = string.Join(",", indices);
154+
var cmds = indices.Select(i => _createCommand("add", new AliasParams { Index = i, Alias = alias }));
155+
var q = string.Join(",", cmds);
156156
return this._Alias(q);
157157
}
158158
/// <summary>
@@ -177,7 +177,7 @@ public IIndicesOperationResponse Alias(AliasParams aliasParams)
177177
public IIndicesOperationResponse Alias(IEnumerable<AliasParams> aliases)
178178
{
179179
var cmds = aliases.Select(a => _aliasBody.F(_createCommand("add", a)));
180-
var q = string.Join(",", aliases);
180+
var q = string.Join(",", cmds);
181181
return this._Alias(q);
182182
}
183183
/// <summary>
@@ -193,7 +193,7 @@ public IIndicesOperationResponse RemoveAlias(AliasParams aliasParams)
193193
public IIndicesOperationResponse RemoveAliases(IEnumerable<AliasParams> aliases)
194194
{
195195
var cmds = aliases.Select(a => _aliasBody.F(_createCommand("remove", a)));
196-
var q = string.Join(",", aliases);
196+
var q = string.Join(",", cmds);
197197
return this._Alias(q);
198198
}
199199
private IndicesOperationResponse _Alias(string query)

src/Nest/IRawElasticClient.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Nest
1414
///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec
1515
///</pre>
1616
///<pre>
17-
///Generated of commit 3cda53fff894d3231d575d0d241aefa51a78b0c1
17+
///Generated of commit 38b6771b55
1818
///</pre>
1919
///</summary>
2020
public interface IRawElasticClient
@@ -1117,6 +1117,16 @@ public interface IRawElasticClient
11171117
///<param name="index">A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices</param>
11181118
Task<ConnectionStatus> IndicesGetSettingsGetAsync(string index, NameValueCollection queryString = null);
11191119

1120+
///<summary>GET /_template
1121+
///<pre>http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/</pre>
1122+
///</summary>
1123+
ConnectionStatus IndicesGetTemplateGet(NameValueCollection queryString = null);
1124+
1125+
///<summary>GET /_template
1126+
///<pre>http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/</pre>
1127+
///</summary>
1128+
Task<ConnectionStatus> IndicesGetTemplateGetAsync(NameValueCollection queryString = null);
1129+
11201130
///<summary>GET /_template/{name}
11211131
///<pre>http://www.elasticsearch.org/guide/reference/api/admin-indices-templates/</pre>
11221132
///</summary>

src/Nest/Nest.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
<Compile Include="ExposedInternals\ElasticInferrer.cs" />
7474
<Compile Include="ExposedInternals\ElasticSerializer.cs" />
7575
<Compile Include="Exception\ConnectionException.cs" />
76+
<Compile Include="QueryStringParameters\BaseQueryStringParameters.cs" />
77+
<Compile Include="QueryStringParameters\GeneratedQueryStringParameters.cs" />
7678
<Compile Include="RawElasticClient-Generated.cs" />
7779
<Compile Include="Extensions\StringInject.cs" />
7880
<Compile Include="RawElasticClient.cs" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace Nest.QueryStringParameters
8+
{
9+
/// <summary>
10+
/// Used by the raw client to compose querystring parameters in a matter that still exposes some xmldocs
11+
/// You can always pass a simple NameValueCollection if you want.
12+
/// </summary>
13+
/// <typeparam name="T"></typeparam>
14+
public class FluentQueryString<T> : NameValueCollection where T : FluentQueryString<T>
15+
{
16+
public new T Add(string name, string value)
17+
{
18+
base.Add(name, value);
19+
return (T)this;
20+
}
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Nest.QueryStringParameters
7+
{
8+
class GeneratedQueryStringParameters
9+
{
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
///This file contains all the typed querystring parameters that are generated of the client spec.
7+
///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec
8+
///Generated of commit @Model.Commit
9+
10+
namespace Nest.QueryStringParameters
11+
{
12+
13+
14+
}

src/ScriptCs.Generate.RawClient/Views/IRawElasticClient.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace Nest
1414
///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec
1515
///</pre>
1616
///<pre>
17-
///Generated of commit 3cda53fff894d3231d575d0d241aefa51a78b0c1
17+
///Generated of commit @Model.Commit
1818
///</pre>
1919
///</summary>
2020
public interface IRawElasticClient
2121
{
22-
@foreach(var kv in Model)
22+
@foreach(var kv in Model.Endpoints)
2323
{
2424
var identifier = kv.Key;
2525
var endpoint = kv.Value;

src/ScriptCs.Generate.RawClient/api.csx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ using Xipton.Razor;
55
using System.IO;
66
using System.Globalization;
77

8+
9+
public class RestApiSpec {
10+
public string Commit { get; set; }
11+
public IDictionary<string, ApiEndpoint> Endpoints { get; set; }
12+
13+
public IList<ApiQueryParameters> ApiQueryParameters { get; set; }
14+
}
15+
816
public class ApiEndpoint {
917
public string CsharpMethodName { get; set; }
1018
public string Documentation { get; set; }
@@ -66,7 +74,14 @@ public class ApiEndpoint {
6674
Description = this.Body.Description
6775
});
6876
}
69-
args = args.Concat(new [] { "NameValueCollection queryString = null" });
77+
var queryStringParamName = "FluentQueryString";
78+
if (this.Url.Params != null && this.Url.Params.Any())
79+
queryStringParamName = methodName + "QueryString";
80+
81+
args = args.Concat(new []
82+
{
83+
"Func<"+queryStringParamName+", NameValueCollection> queryString = null"
84+
});
7085

7186
var apiMethod = new CsharpMethod
7287
{
@@ -115,6 +130,7 @@ public class ApiUrl {
115130
public IDictionary<string, ApiUrlPart> Parts { get; set; }
116131
public IDictionary<string, ApiQueryParameters> Params { get; set; }
117132
}
133+
118134
public class ApiUrlPart {
119135
public string Name { get; set; }
120136
public string Type { get; set; }
@@ -140,7 +156,7 @@ public static class ApiGenerator
140156
var textInfo = new CultureInfo("en-US").TextInfo;
141157
return textInfo.ToTitleCase(s.ToLowerInvariant()).Replace("_", string.Empty).Replace(".", string.Empty);
142158
}
143-
public static IDictionary<string, ApiEndpoint> GetAllApiEndpoints()
159+
public static RestApiSpec GetRestSpec()
144160
{
145161
Console.WriteLine("Getting a listing of all the api endpoints from the elasticsearch-rest-api-spec repos");
146162
var dom = CQ.CreateFromUrl(_listingUrl);
@@ -163,7 +179,13 @@ public static class ApiGenerator
163179
})
164180
.ToDictionary(d=>d.Key, d=>d.Value);
165181

166-
return endpoints;
182+
var restSpec = new RestApiSpec {
183+
Endpoints = endpoints,
184+
Commit = dom[".sha:first"].Text()
185+
};
186+
187+
188+
return restSpec;
167189
}
168190

169191
//Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
@@ -185,24 +207,31 @@ public static class ApiGenerator
185207
if (method.Path.Contains("/fielddata/"))
186208
method.FullName = method.FullName.Replace("Stats", "FieldDataStats");
187209
}
188-
189-
190210
}
211+
191212
public static string CreateMethodName(string apiEnpointKey, ApiEndpoint endpoint)
192213
{
193214
return PascalCase(apiEnpointKey);
194215
}
195216

196-
public static void GenerateClientInterface(IDictionary<string, ApiEndpoint> model)
217+
public static void GenerateClientInterface(RestApiSpec model)
197218
{
198219
var targetFile = @"..\Nest\IRawElasticClient.cs";
199220
var source = _razorMachine.Execute(File.ReadAllText(@"Views\IRawElasticClient.cshtml"), model).ToString();
200221
File.WriteAllText(targetFile, source);
201222
}
223+
224+
public static void GenerateQueryStringParameters(RestApiSpec model)
225+
{
226+
var targetFile = @"..\Nest\QueryStringParameters\GeneratedQueryStringParameters.cs";
227+
var source = _razorMachine.Execute(File.ReadAllText(@"Views\GeneratedQueryStringParameters.cshtml"), model).ToString();
228+
File.WriteAllText(targetFile, source);
229+
}
202230
}
203231

204232

205-
//extensions methods dont work becuase scriptcs wraps everything.
233+
//extensions methods dont work because scriptcs wraps everything
234+
//in its own class
206235
public static class Extensions {
207236
public static IEnumerable<T> DistinctBy<T, TKey>(IEnumerable<T> items, Func<T, TKey> property)
208237
{

src/ScriptCs.Generate.RawClient/app.csx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ using System.Net;
44
using CsQuery;
55
using Newtonsoft.Json;
66

7-
var apiEndpoints = ApiGenerator.GetAllApiEndpoints();
7+
var spec = ApiGenerator.GetRestSpec();
88

9-
ApiGenerator.GenerateClientInterface(apiEndpoints);
9+
ApiGenerator.GenerateClientInterface(spec);
1010

11-
Console.WriteLine("Found {0} api documentation endpoints", apiEndpoints.Count());
11+
ApiGenerator.GenerateQueryStringParameters(spec);
12+
13+
Console.WriteLine("Found {0} api documentation endpoints", spec.Endpoints.Count());

0 commit comments

Comments
 (0)