Skip to content

Commit dc2790f

Browse files
committed
Merge pull request #744 from elasticsearch/feature/normalize-enums
Feature/normalize enums
2 parents 74e0694 + ac74035 commit dc2790f

File tree

194 files changed

+1196
-1389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+1196
-1389
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiGenerator.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,25 @@ public static void PatchMethod(CsharpMethod method)
155155
var overrides = Activator.CreateInstance(type) as IDescriptorOverrides;
156156
if (overrides == null)
157157
return;
158-
method.Url.Params = method.Url.Params.Where(p => !overrides.SkipQueryStringParams.Contains(p.Key))
159-
.ToDictionary(k => k.Key, v => v.Value);
158+
159+
foreach (var kv in method.Url.Params)
160+
{
161+
if (overrides.SkipQueryStringParams.Contains(kv.Key))
162+
method.Url.Params.Remove(kv.Key);
163+
164+
if (overrides.RenameQueryStringParams == null) continue;
165+
166+
string newName;
167+
if (!overrides.RenameQueryStringParams.TryGetValue(kv.Key, out newName))
168+
continue;
169+
170+
method.Url.Params.Remove(kv.Key);
171+
method.Url.Params.Add(newName, kv.Value);
172+
173+
}
174+
175+
//method.Url.Params = method.Url.Params.Where(p => !overrides.SkipQueryStringParams.Contains(p.Key))
176+
// .ToDictionary(k => k.Key, v => v.Value);
160177
}
161178
// ReSharper disable once EmptyGeneralCatchClause
162179
catch

src/CodeGeneration/CodeGeneration.LowLevelClient/CodeGeneration.LowLevelClient.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
<Compile Include="Domain\CsharpMethod.cs" />
8080
<Compile Include="Extensions.cs" />
8181
<Compile Include="Overrides\Allow404\ApiEndpointsThatAllow404.cs" />
82+
<Compile Include="Overrides\Descriptors\IDescriptorOverrides.cs" />
83+
<Compile Include="Overrides\Descriptors\NodesHotThreadsDescriptorOverrides.cs" />
8284
<Compile Include="Overrides\Descriptors\DeleteWarmerDescriptorOverrides.cs" />
8385
<Compile Include="Overrides\Descriptors\PutTemplateDescriptorOverrides.cs" />
8486
<Compile Include="Overrides\Descriptors\ClearCacheDescriptorOverrides.cs" />

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public IEnumerable<CsharpMethod> CsharpMethods
123123
case "list":
124124
return "string " + p.Name;
125125
case "enum":
126-
return this.PascalCase(p.Name) + "Options " + p.Name;
126+
return this.PascalCase(p.Name) + p.Name;
127127
default:
128128
return p.Type + " " + p.Name;
129129
//return "string " + p.Name;

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiQueryParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public string CsharpType(string paramName)
2727
case null:
2828
return "string";
2929
case "enum":
30-
return paramName.ToPascalCase() + "Options";
30+
return paramName.ToPascalCase();
3131
default:
3232
return this.Type;
3333
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/RestApiSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public IEnumerable<EnumDescription> EnumsInTheSpec
2424
get
2525
{
2626
var queryParamEnums = from m in this.CsharpMethodsWithQueryStringInfo.SelectMany(m => m.Url.Params)
27-
where m.Value.CsharpType(m.Key).EndsWith("Options")
27+
where m.Value.Type == "enum"
2828
select new EnumDescription
2929
{
3030
Name = m.Value.CsharpType(m.Key),

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Descriptors/ClearCacheDescriptorOverrides.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ public IEnumerable<string> SkipQueryStringParams
1717
};
1818
}
1919
}
20+
21+
public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
2022
}
2123
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Descriptors/DeleteWarmerDescriptorOverrides.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ public IEnumerable<string> SkipQueryStringParams
1717
};
1818
}
1919
}
20+
21+
public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
2022
}
2123
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
3+
namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
4+
{
5+
/// <summary>
6+
/// Tweaks the generated descriptors
7+
/// </summary>
8+
public interface IDescriptorOverrides
9+
{
10+
/// <summary>
11+
/// Sometimes params can be defined on the body as well as on the querystring
12+
/// We favor specifying params on the body so here we can specify params we don't want on the querystring.
13+
/// </summary>
14+
IEnumerable<string> SkipQueryStringParams { get; }
15+
16+
/// <summary>
17+
/// Override how the query param name is exposed to the client.
18+
/// </summary>
19+
IDictionary<string, string> RenameQueryStringParams { get; }
20+
}
21+
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Descriptors/MultiTermVectorsDescriptorOverrides.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public IEnumerable<string> SkipQueryStringParams
1818
};
1919
}
2020
}
21+
public IDictionary<string, string> RenameQueryStringParams { get { return null; } }
2122
}
2223
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CodeGeneration.LowLevelClient.Overrides.Descriptors
7+
{
8+
public class NodesHotThreadsDescriptorOverrides : IDescriptorOverrides
9+
{
10+
public IEnumerable<string> SkipQueryStringParams
11+
{
12+
get
13+
{
14+
return new string[]
15+
{
16+
"fielddata"
17+
};
18+
}
19+
}
20+
public IDictionary<string, string> RenameQueryStringParams
21+
{
22+
get
23+
{
24+
return new Dictionary<string, string>
25+
{
26+
{ "type", "thread_type"}
27+
};
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)