Skip to content

Commit e42784e

Browse files
committed
fix ApiGenerator style violations
(cherry picked from commit e1b89de)
1 parent 33d96df commit e42784e

File tree

12 files changed

+20
-37
lines changed

12 files changed

+20
-37
lines changed

src/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ public static Dictionary<string, string> ApiNameMapping
140140
if (_apiNameMapping != null) return _apiNameMapping;
141141
lock (LowLevelApiNameMapping)
142142
{
143-
if (_apiNameMapping != null) return _apiNameMapping;
144-
145-
var mapping = new Dictionary<string,string>(HighLevelApiNameMapping);
146-
foreach (var (k, v) in LowLevelApiNameMapping)
147-
mapping[k] = v;
148-
_apiNameMapping = mapping;
143+
if (_apiNameMapping == null)
144+
{
145+
var mapping = new Dictionary<string, string>(HighLevelApiNameMapping);
146+
foreach (var (k, v) in LowLevelApiNameMapping)
147+
mapping[k] = v;
148+
_apiNameMapping = mapping;
149+
}
149150
return _apiNameMapping;
150151
}
151152
}

src/ApiGenerator/Domain/Code/CsharpNames.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ string Replace(string original, string ns, string find, string replace, string[]
3838
var namespaceRenames = new Dictionary<string, (string find, string replace, string[] exceptions)>
3939
{
4040
{ "Watcher", (find: "Watch", replace: "", exceptions: new string[0]) },
41-
{ "Indices", (find: "Index", replace: "", exceptions: new string[] { "SimulateIndexTemplate" }) },
41+
{ "Indices", (find: "Index", replace: "", exceptions: new [] { "SimulateIndexTemplate" }) },
4242
{ "CrossClusterReplication", (find: "Ccr", replace: "", exceptions: new string[0]) },
4343
{ "IndexLifecycleManagement", (find: "Ilm", replace: "", exceptions: new string[0]) },
4444
{ "SnapshotLifecycleManagement", (find: "Slm", replace: "", exceptions: new string[0]) },

src/ApiGenerator/Generator/ApiEndpointFactory.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static void PatchRequestParameters(ApiEndpoint endpoint)
8787
private static void PatchOfficialSpec(JObject original, string jsonFile)
8888
{
8989
var directory = Path.GetDirectoryName(jsonFile);
90-
var patchFile = Path.Combine(directory,"..", "_Patches", Path.GetFileNameWithoutExtension(jsonFile)) + ".patch.json";
90+
var patchFile = Path.Combine(directory!,"..", "_Patches", Path.GetFileNameWithoutExtension(jsonFile)) + ".patch.json";
9191
if (!File.Exists(patchFile)) return;
9292

9393
var patchedJson = JObject.Parse(File.ReadAllText(patchFile));
@@ -103,9 +103,7 @@ private static void PatchOfficialSpec(JObject original, string jsonFile)
103103

104104
var methodsOverride = patchedJson.SelectToken("*.methods");
105105
if (methodsOverride != null)
106-
{
107106
original.SelectToken("*.methods").Replace(methodsOverride);
108-
}
109107

110108
var paramsOverride = patchedJson.SelectToken("*.params");
111109
var originalParams = original.SelectToken("*.url.params") as JObject;
@@ -179,7 +177,7 @@ private static void TransformNewSpecStructureToOld(JObject original)
179177

180178
var newUrl = new JObject
181179
{
182-
["paths"] = new JArray(paths.ToArray()),
180+
["paths"] = new JArray(paths.Cast<object>().ToArray()),
183181
};
184182

185183
if (spec.ContainsKey("params"))
@@ -192,10 +190,10 @@ private static void TransformNewSpecStructureToOld(JObject original)
192190
newUrl["parts"] = parts;
193191

194192
if (deprecatedPaths.Any())
195-
newUrl["deprecated_paths"] = new JArray(deprecatedPaths.ToArray());
193+
newUrl["deprecated_paths"] = new JArray(deprecatedPaths.Cast<object>().ToArray());
196194

197195
spec["url"] = newUrl;
198-
spec["methods"] = new JArray(methods.ToArray());
196+
spec["methods"] = new JArray(methods.Cast<object>().ToArray());
199197
}
200198
}
201199
}

src/ApiGenerator/Generator/ApiGenerator.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ApiGenerator
2222

2323
public static async Task Generate(string downloadBranch, bool lowLevelOnly, RestApiSpec spec)
2424
{
25-
async Task Generate(IList<RazorGeneratorBase> generators, RestApiSpec restApiSpec, bool highLevel)
25+
static async Task DoGenerate(ICollection<RazorGeneratorBase> generators, RestApiSpec restApiSpec, bool highLevel)
2626
{
2727
var pbarOpts = new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray };
2828
var message = $"Generating {(highLevel ? "high" : "low")} level code";
@@ -55,17 +55,15 @@ async Task Generate(IList<RazorGeneratorBase> generators, RestApiSpec restApiSpe
5555
new RequestsGenerator(),
5656
};
5757

58-
await Generate(lowLevelGenerators, spec, highLevel: false);
58+
await DoGenerate(lowLevelGenerators, spec, highLevel: false);
5959
if (!lowLevelOnly)
60-
await Generate(highLevelGenerators, spec, highLevel: true);
60+
await DoGenerate(highLevelGenerators, spec, highLevel: true);
6161

6262
// Check if there are any non-Stable endpoints present.
6363
foreach (var endpoint in spec.Endpoints)
6464
{
6565
if (endpoint.Value.Stability != Stability.Stable)
66-
{
6766
Warnings.Add($"Endpoint {endpoint.Value.Name} is not marked as Stable ({endpoint.Value.Stability})");
68-
}
6967
}
7068

7169
if (Warnings.Count == 0) return;

src/ApiGenerator/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private static async Task Main(string[] args)
3636
if (string.IsNullOrEmpty(downloadBranch))
3737
downloadBranch = DownloadBranch;
3838

39-
var generateCode = Ask("Generate code from the specification files on disk?", true);
40-
var lowLevelOnly = generateCode && Ask("Generate low level client only?", false);
39+
var generateCode = Ask("Generate code from the specification files on disk?", defaultAnswer: true);
40+
var lowLevelOnly = generateCode && Ask("Generate low level client only?", defaultAnswer: false);
4141

4242
if (redownloadCoreSpecification)
4343
RestSpecDownloader.Download(downloadBranch);

src/ApiGenerator/Views/HighLevel/Client/Implementation/ElasticClient.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using Nest;
1313

1414
@{
1515
RestApiSpec model = Model;
16-
var namespaces = model.EndpointsPerNamespaceHighLevel.Keys.Where(k => k != CsharpNames.RootNamespace);
16+
var namespaces = model.EndpointsPerNamespaceHighLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
1717
<text>
1818
// ReSharper disable RedundantTypeArgumentsOfMethod
1919
namespace Nest

src/ApiGenerator/Views/HighLevel/Client/Usings.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
{
88
<text>using Nest.@(CsharpNames.ApiNamespace).@(kv.Key)@(CsharpNames.ApiNamespaceSuffix);
99
</text>
10-
continue;
1110
}
1211
}

src/ApiGenerator/Views/HighLevel/Descriptors/RequestDescriptorBase.cshtml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
@using ApiGenerator.Domain
22
@inherits ApiGenerator.CodeTemplatePage<RestApiSpec>
3-
@{
4-
RestApiSpec m = Model;
5-
}
63
using System.Collections.Generic;
74

85
namespace Nest

src/ApiGenerator/Views/HighLevel/Requests/PlainRequestBase.cshtml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
@using System.Linq
22
@using ApiGenerator.Domain
33
@inherits ApiGenerator.CodeTemplatePage<RestApiSpec>
4-
@{
5-
RestApiSpec m = Model;
6-
}
74
@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
85
// ReSharper disable RedundantUsingDirective
96
using System;

src/ApiGenerator/Views/LowLevel/Client/Implementation/ElasticLowLevelClient.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using static Elasticsearch.Net.HttpMethod;
1818

1919
@{
2020
RestApiSpec model = Model;
21-
var namespaces = model.EndpointsPerNamespaceLowLevel.Keys.Where(k => k != CsharpNames.RootNamespace);
21+
var namespaces = model.EndpointsPerNamespaceLowLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
2222
<text>
2323
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
2424
// ReSharper disable RedundantExtendsListEntry

0 commit comments

Comments
 (0)