Skip to content

Commit 1cd084e

Browse files
committed
fixed renamed querystring parameters not using the original querystring param name in the request, SourceEnabled was typed technically correct but not practically, added a way to deprecate requestparams and added EnableSource instead
1 parent 64ec19c commit 1cd084e

File tree

8 files changed

+230
-65
lines changed

8 files changed

+230
-65
lines changed

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/ApiGenerator.cs

+22-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using CodeGeneration.LowLevelClient.Overrides.Allow404;
1111
using CodeGeneration.LowLevelClient.Overrides.Descriptors;
1212
using CsQuery;
13+
using CsQuery.ExtensionMethods.Internal;
1314
using Newtonsoft.Json;
1415
using Xipton.Razor;
1516

@@ -189,22 +190,37 @@ public static void PatchMethod(CsharpMethod method)
189190
if (!renameList.ContainsKey(kv.Key))
190191
renameList[kv.Key] = kv.Value;
191192

193+
var patchedParams = new Dictionary<string, ApiQueryParameters>();
192194
foreach (var kv in method.Url.Params)
193195
{
196+
if (kv.Value.OriginalQueryStringParamName.IsNullOrEmpty())
197+
kv.Value.OriginalQueryStringParamName = kv.Key;
194198
if (skipList.Contains(kv.Key))
195-
{
196-
method.Url.Params.Remove(kv.Key);
197199
continue;
198-
}
199200

200201
string newName;
201202
if (!renameList.TryGetValue(kv.Key, out newName))
203+
{
204+
patchedParams.Add(kv.Key, kv.Value);
202205
continue;
206+
}
207+
208+
patchedParams.Add(newName, kv.Value);
203209

204-
method.Url.Params.Remove(kv.Key);
205-
method.Url.Params.Add(newName, kv.Value);
206-
210+
if (newName == "source_enabled")
211+
{
212+
kv.Value.DeprecatedInFavorOf = "EnableSource";
213+
patchedParams.Add("enable_source", new ApiQueryParameters
214+
{
215+
Description = kv.Value.Description,
216+
Options = kv.Value.Options,
217+
Type = "boolean",
218+
OriginalQueryStringParamName = "_source"
219+
});
220+
}
207221
}
222+
223+
method.Url.Params = patchedParams;
208224
}
209225
// ReSharper disable once EmptyGeneralCatchClause
210226
catch

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiQueryParameters.cs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace CodeGeneration.LowLevelClient.Domain
55
{
66
public class ApiQueryParameters
77
{
8+
public string OriginalQueryStringParamName { get; set; }
9+
public string DeprecatedInFavorOf { get; set; }
810
public string Type { get; set; }
911
public string Description { get; set; }
1012
public IEnumerable<string> Options { get; set; }

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Views/RequestParameters.Generated.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace Elasticsearch.Net
4747
public @method.QueryStringParamName @(mm.ToPascalCase())(@kv.Value.CsharpType(mm) @mm)
4848
{
4949
this._@(mm) = @Raw(setter);
50-
this.AddQueryString("@mm", this._@mm);
50+
this.AddQueryString("@kv.Value.OriginalQueryStringParamName", this._@mm);
5151
return this;
5252
}
5353
</text>

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Descriptors.Generated.cshtml

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace Nest
4343
var fieldMethod = (mml.Contains("fields") || mml.Contains("sourceinclude") || mml.Contains("sourceexclude") ) && t.Contains("string");
4444
<text>
4545
///<summary>@kv.Value.Description</summary>
46+
@if(!string.IsNullOrWhiteSpace(kv.Value.DeprecatedInFavorOf))
47+
{
48+
<text>[Obsolete("Scheduled to be removed in 2.0, use @kv.Value.DeprecatedInFavorOf instead")]</text>
49+
}
4650
public @Raw(type) @(mm)(@t @kv.Key@tSuffix)
4751
{
4852
this.Request.RequestParameters.@(m)(@kv.Key);

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Requests.Generated.cshtml

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace Nest
3939
{
4040
@foreach (KeyValuePair<string, ApiQueryParameters> kv in method.Url.Params)
4141
{
42-
var original = kv.Key;
42+
var original = kv.Value.OriginalQueryStringParamName;
4343
var cased = kv.Key.ToPascalCase();
4444
var mm = (cased != "Type" && cased != "Index" && cased != "Script") ? cased : cased + "QueryString";
4545
var fieldType = kv.Value.CsharpType(kv.Key).Replace("params", "");
@@ -54,6 +54,10 @@ namespace Nest
5454
}
5555
<text>
5656
///<summary>@kv.Value.Description</summary>
57+
@if(!string.IsNullOrWhiteSpace(kv.Value.DeprecatedInFavorOf))
58+
{
59+
<text>[Obsolete("Scheduled to be removed in 2.0, use @kv.Value.DeprecatedInFavorOf instead")]</text>
60+
}
5761
public @Raw(fieldType) @(mm)
5862
{
5963
get { return this.Request.RequestParameters.GetQueryStringValue@(Raw("<" + fieldType + ">"))("@original"); }

Diff for: src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

+53-13
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,17 @@ public ExplainRequestParameters Source(string source)
18761876
public ExplainRequestParameters SourceEnabled(params string[] source_enabled)
18771877
{
18781878
this._source_enabled = source_enabled;
1879-
this.AddQueryString("source_enabled", this._source_enabled);
1879+
this.AddQueryString("_source", this._source_enabled);
1880+
return this;
1881+
}
1882+
1883+
1884+
internal bool _enable_source { get; set; }
1885+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1886+
public ExplainRequestParameters EnableSource(bool enable_source)
1887+
{
1888+
this._enable_source = enable_source;
1889+
this.AddQueryString("_source", this._enable_source);
18801890
return this;
18811891
}
18821892

@@ -1886,7 +1896,7 @@ public ExplainRequestParameters SourceEnabled(params string[] source_enabled)
18861896
public ExplainRequestParameters SourceExclude(params string[] source_exclude)
18871897
{
18881898
this._source_exclude = source_exclude.Select(f=>(object)f);
1889-
this.AddQueryString("source_exclude", this._source_exclude);
1899+
this.AddQueryString("_source_exclude", this._source_exclude);
18901900
return this;
18911901
}
18921902

@@ -1896,7 +1906,7 @@ public ExplainRequestParameters SourceExclude(params string[] source_exclude)
18961906
public ExplainRequestParameters SourceInclude(params string[] source_include)
18971907
{
18981908
this._source_include = source_include.Select(f=>(object)f);
1899-
this.AddQueryString("source_include", this._source_include);
1909+
this.AddQueryString("_source_include", this._source_include);
19001910
return this;
19011911
}
19021912

@@ -1976,7 +1986,17 @@ public GetRequestParameters Routing(string routing)
19761986
public GetRequestParameters SourceEnabled(params string[] source_enabled)
19771987
{
19781988
this._source_enabled = source_enabled;
1979-
this.AddQueryString("source_enabled", this._source_enabled);
1989+
this.AddQueryString("_source", this._source_enabled);
1990+
return this;
1991+
}
1992+
1993+
1994+
internal bool _enable_source { get; set; }
1995+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1996+
public GetRequestParameters EnableSource(bool enable_source)
1997+
{
1998+
this._enable_source = enable_source;
1999+
this.AddQueryString("_source", this._enable_source);
19802000
return this;
19812001
}
19822002

@@ -1986,7 +2006,7 @@ public GetRequestParameters SourceEnabled(params string[] source_enabled)
19862006
public GetRequestParameters SourceExclude(params string[] source_exclude)
19872007
{
19882008
this._source_exclude = source_exclude.Select(f=>(object)f);
1989-
this.AddQueryString("source_exclude", this._source_exclude);
2009+
this.AddQueryString("_source_exclude", this._source_exclude);
19902010
return this;
19912011
}
19922012

@@ -1996,7 +2016,7 @@ public GetRequestParameters SourceExclude(params string[] source_exclude)
19962016
public GetRequestParameters SourceInclude(params string[] source_include)
19972017
{
19982018
this._source_include = source_include.Select(f=>(object)f);
1999-
this.AddQueryString("source_include", this._source_include);
2019+
this.AddQueryString("_source_include", this._source_include);
20002020
return this;
20012021
}
20022022

@@ -2086,7 +2106,17 @@ public SourceRequestParameters Routing(string routing)
20862106
public SourceRequestParameters SourceEnabled(params string[] source_enabled)
20872107
{
20882108
this._source_enabled = source_enabled;
2089-
this.AddQueryString("source_enabled", this._source_enabled);
2109+
this.AddQueryString("_source", this._source_enabled);
2110+
return this;
2111+
}
2112+
2113+
2114+
internal bool _enable_source { get; set; }
2115+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
2116+
public SourceRequestParameters EnableSource(bool enable_source)
2117+
{
2118+
this._enable_source = enable_source;
2119+
this.AddQueryString("_source", this._enable_source);
20902120
return this;
20912121
}
20922122

@@ -2096,7 +2126,7 @@ public SourceRequestParameters SourceEnabled(params string[] source_enabled)
20962126
public SourceRequestParameters SourceExclude(params string[] source_exclude)
20972127
{
20982128
this._source_exclude = source_exclude.Select(f=>(object)f);
2099-
this.AddQueryString("source_exclude", this._source_exclude);
2129+
this.AddQueryString("_source_exclude", this._source_exclude);
21002130
return this;
21012131
}
21022132

@@ -2106,7 +2136,7 @@ public SourceRequestParameters SourceExclude(params string[] source_exclude)
21062136
public SourceRequestParameters SourceInclude(params string[] source_include)
21072137
{
21082138
this._source_include = source_include.Select(f=>(object)f);
2109-
this.AddQueryString("source_include", this._source_include);
2139+
this.AddQueryString("_source_include", this._source_include);
21102140
return this;
21112141
}
21122142

@@ -4166,7 +4196,17 @@ public MultiGetRequestParameters Refresh(bool refresh)
41664196
public MultiGetRequestParameters SourceEnabled(params string[] source_enabled)
41674197
{
41684198
this._source_enabled = source_enabled;
4169-
this.AddQueryString("source_enabled", this._source_enabled);
4199+
this.AddQueryString("_source", this._source_enabled);
4200+
return this;
4201+
}
4202+
4203+
4204+
internal bool _enable_source { get; set; }
4205+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
4206+
public MultiGetRequestParameters EnableSource(bool enable_source)
4207+
{
4208+
this._enable_source = enable_source;
4209+
this.AddQueryString("_source", this._enable_source);
41704210
return this;
41714211
}
41724212

@@ -4176,7 +4216,7 @@ public MultiGetRequestParameters SourceEnabled(params string[] source_enabled)
41764216
public MultiGetRequestParameters SourceExclude(params string[] source_exclude)
41774217
{
41784218
this._source_exclude = source_exclude.Select(f=>(object)f);
4179-
this.AddQueryString("source_exclude", this._source_exclude);
4219+
this.AddQueryString("_source_exclude", this._source_exclude);
41804220
return this;
41814221
}
41824222

@@ -4186,7 +4226,7 @@ public MultiGetRequestParameters SourceExclude(params string[] source_exclude)
41864226
public MultiGetRequestParameters SourceInclude(params string[] source_include)
41874227
{
41884228
this._source_include = source_include.Select(f=>(object)f);
4189-
this.AddQueryString("source_include", this._source_include);
4229+
this.AddQueryString("_source_include", this._source_include);
41904230
return this;
41914231
}
41924232

@@ -4596,7 +4636,7 @@ public NodesHotThreadsRequestParameters Threads(long threads)
45964636
public NodesHotThreadsRequestParameters ThreadType(ThreadType thread_type)
45974637
{
45984638
this._thread_type = thread_type;
4599-
this.AddQueryString("thread_type", this._thread_type);
4639+
this.AddQueryString("type", this._thread_type);
46004640
return this;
46014641
}
46024642

Diff for: src/Nest/DSL/_Descriptors.generated.cs

+36
Original file line numberDiff line numberDiff line change
@@ -1778,13 +1778,22 @@ public ExplainDescriptor<T> Source(string source)
17781778

17791779

17801780
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1781+
[Obsolete("Scheduled to be removed in 2.0, use EnableSource instead")]
17811782
public ExplainDescriptor<T> SourceEnabled(params string[] source_enabled)
17821783
{
17831784
this.Request.RequestParameters.SourceEnabled(source_enabled);
17841785
return this;
17851786
}
17861787

17871788

1789+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1790+
public ExplainDescriptor<T> EnableSource(bool enable_source = true)
1791+
{
1792+
this.Request.RequestParameters.EnableSource(enable_source);
1793+
return this;
1794+
}
1795+
1796+
17881797
///<summary>A list of fields to exclude from the returned _source field</summary>
17891798
public ExplainDescriptor<T> SourceExclude(params string[] source_exclude)
17901799
{
@@ -1896,13 +1905,22 @@ public GetDescriptor<T> Routing(string routing)
18961905

18971906

18981907
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1908+
[Obsolete("Scheduled to be removed in 2.0, use EnableSource instead")]
18991909
public GetDescriptor<T> SourceEnabled(params string[] source_enabled)
19001910
{
19011911
this.Request.RequestParameters.SourceEnabled(source_enabled);
19021912
return this;
19031913
}
19041914

19051915

1916+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
1917+
public GetDescriptor<T> EnableSource(bool enable_source = true)
1918+
{
1919+
this.Request.RequestParameters.EnableSource(enable_source);
1920+
return this;
1921+
}
1922+
1923+
19061924
///<summary>A list of fields to exclude from the returned _source field</summary>
19071925
public GetDescriptor<T> SourceExclude(params string[] source_exclude)
19081926
{
@@ -2011,13 +2029,22 @@ public SourceDescriptor<T> Routing(string routing)
20112029

20122030

20132031
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
2032+
[Obsolete("Scheduled to be removed in 2.0, use EnableSource instead")]
20142033
public SourceDescriptor<T> SourceEnabled(params string[] source_enabled)
20152034
{
20162035
this.Request.RequestParameters.SourceEnabled(source_enabled);
20172036
return this;
20182037
}
20192038

20202039

2040+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
2041+
public SourceDescriptor<T> EnableSource(bool enable_source = true)
2042+
{
2043+
this.Request.RequestParameters.EnableSource(enable_source);
2044+
return this;
2045+
}
2046+
2047+
20212048
///<summary>A list of fields to exclude from the returned _source field</summary>
20222049
public SourceDescriptor<T> SourceExclude(params string[] source_exclude)
20232050
{
@@ -3998,13 +4025,22 @@ public MultiGetDescriptor Refresh(bool refresh = true)
39984025

39994026

40004027
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
4028+
[Obsolete("Scheduled to be removed in 2.0, use EnableSource instead")]
40014029
public MultiGetDescriptor SourceEnabled(params string[] source_enabled)
40024030
{
40034031
this.Request.RequestParameters.SourceEnabled(source_enabled);
40044032
return this;
40054033
}
40064034

40074035

4036+
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
4037+
public MultiGetDescriptor EnableSource(bool enable_source = true)
4038+
{
4039+
this.Request.RequestParameters.EnableSource(enable_source);
4040+
return this;
4041+
}
4042+
4043+
40084044
///<summary>A list of fields to exclude from the returned _source field</summary>
40094045
public MultiGetDescriptor SourceExclude(params string[] source_exclude)
40104046
{

0 commit comments

Comments
 (0)