Skip to content

Commit 45026fc

Browse files
Mpdreamzrusscam
authored andcommitted
Fix/7.0 ga code generation (#3664)
* Add XPack download location * ask to generate code again as well, allows you to only download the specs without regenerating all the code * move patch files to explicit _Patches folder so they are easier to spot and delete when no longer needed * Create patch files for deprecated paths * Download spec files for 7.0 * skip ccr.forget_follower * patch required on parts automatically and warn if the spec is wrong * Don't download REST API specs by default
1 parent 444856c commit 45026fc

File tree

105 files changed

+3649
-580
lines changed

Some content is hidden

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

105 files changed

+3649
-580
lines changed

src/CodeGeneration/ApiGenerator/ApiGenerator.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,27 @@ private static KeyValuePair<string, ApiEndpoint> CreateApiEndpoint(string jsonFi
133133
var endpoint = officialJsonSpec.ToObject<Dictionary<string, ApiEndpoint>>().First();
134134
endpoint.Value.RestSpecName = endpoint.Key;
135135
endpoint.Value.CsharpMethodName = CreateMethodName(endpoint.Key);
136+
137+
PatchUrlParts(jsonFile, endpoint.Value.Url);
136138
return endpoint;
137139
}
138140

141+
private static void PatchUrlParts(string jsonFile, ApiUrl url)
142+
{
143+
if (url.IsPartless) return;
144+
foreach (var kv in url.Parts)
145+
{
146+
var required = url.ExposedApiPaths.All(p => p.Path.Contains($"{{{kv.Key}}}"));
147+
if (kv.Value.Required != required)
148+
Warnings.Add($"{jsonFile} has part: {kv.Key} listed as {kv.Value.Required} but should be {required}");
149+
kv.Value.Required = required;
150+
}
151+
}
152+
139153
private static void PatchOfficialSpec(JObject original, string jsonFile)
140154
{
141155
var directory = Path.GetDirectoryName(jsonFile);
142-
var patchFile = Path.Combine(directory, Path.GetFileNameWithoutExtension(jsonFile)) + ".patch.json";
156+
var patchFile = Path.Combine(directory,"..", "_Patches", Path.GetFileNameWithoutExtension(jsonFile)) + ".patch.json";
143157
if (!File.Exists(patchFile)) return;
144158

145159
var patchedJson = JObject.Parse(File.ReadAllText(patchFile));

src/CodeGeneration/ApiGenerator/ApiGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313
<ItemGroup>
1414
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
15-
<PackageReference Include="ShellProgressBar" Version="4.1.1" />
15+
<PackageReference Include="ShellProgressBar" Version="4.2.0" />
1616
<PackageReference Include="CsQuery.Core" Version="2.0.1" />
1717
<!-- https://github.com/toddams/RazorLight/issues/172 -->
1818
<PackageReference Include="RazorLight.Unofficial" Version="2.0.0-beta1.1" />

src/CodeGeneration/ApiGenerator/CodeConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static class CodeConfiguration
5656
"indices.unfreeze.json",
5757

5858
"ccr.follow_info.json",
59+
"ccr.forget_follower.json"
5960
};
6061

6162

src/CodeGeneration/ApiGenerator/Domain/ApiUrl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public IEnumerable<string> Paths
2020
set => _paths = (value ?? Enumerable.Empty<string>()).ToList();
2121
}
2222

23-
public IDictionary<string, ApiUrlPart> Parts { private get; set; }
23+
public IDictionary<string, ApiUrlPart> Parts { get; set; }
2424

2525
public IEnumerable<ApiPath> ExposedApiPaths
2626
{

src/CodeGeneration/ApiGenerator/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public static class Program
1010
private static void Main(string[] args)
1111
{
1212
var redownloadCoreSpecification = false;
13+
var generateCode = false;
1314
var downloadBranch = DownloadBranch;
1415

1516
var answer = "invalid";
1617
while (answer != "y" && answer != "n" && answer != "")
1718
{
18-
Console.Write("Download online rest specifications? [Y/N] (default N): ");
19-
//answer = Console.ReadLine()?.Trim().ToLowerInvariant();
20-
answer = "n";
19+
Console.Write("Download online rest specifications? [y/N] (default N): ");
20+
answer = Console.ReadLine()?.Trim().ToLowerInvariant();
2121
redownloadCoreSpecification = answer == "y";
2222
}
2323

@@ -40,7 +40,15 @@ private static void Main(string[] args)
4040
if (redownloadCoreSpecification)
4141
RestSpecDownloader.Download(downloadBranch);
4242

43-
ApiGenerator.Generate(downloadBranch, "Core", "XPack");
43+
answer = "invalid";
44+
while (answer != "y" && answer != "n" && answer != "")
45+
{
46+
Console.Write("Generate code from the specification files on disk? [Y/n] (default Y): ");
47+
answer = Console.ReadLine()?.Trim().ToLowerInvariant();
48+
generateCode = answer == "y" || answer == "";
49+
}
50+
if (generateCode)
51+
ApiGenerator.Generate(downloadBranch, "Core", "XPack");
4452
}
4553
}
4654
}

src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class RestSpecDownloader
1515
private static readonly Dictionary<string, string> OnlineSpecifications = new Dictionary<string, string>
1616
{
1717
{ "Core", "https://github.com/elastic/elasticsearch/tree/{version}/rest-api-spec/src/main/resources/rest-api-spec/api" },
18+
{ "XPack", "https://github.com/elastic/elasticsearch/tree/{version}/x-pack/plugin/src/test/resources/rest-api-spec/api"}
1819
};
1920

2021
private static readonly ProgressBarOptions SubProgressBarOptions = new ProgressBarOptions
@@ -32,7 +33,6 @@ private RestSpecDownloader(string branch)
3233
let url = kv.Value.Replace("{version}", branch)
3334
select new Specification { FolderOnDisk = kv.Key, Branch = branch, GithubListingUrl = url }).ToList();
3435

35-
3636
using (var pbar = new ProgressBar(specifications.Count, "Downloading specifications", MainProgressBarOptions))
3737
{
3838
foreach (var spec in specifications)

src/CodeGeneration/ApiGenerator/RestSpecification/Core/bulk.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
"methods": ["POST", "PUT"],
55
"url": {
66
"path": "/_bulk",
7-
"paths": ["/_bulk", "/{index}/_bulk"],
8-
"deprecated_paths" : [
9-
{
10-
"version" : "7.0",
11-
"path" : "/{index}/{type}/_bulk",
12-
"description" : "Specifying types in urls has been deprecated"
13-
}
14-
],
7+
"paths": ["/_bulk", "/{index}/_bulk", "/{index}/{type}/_bulk"],
158
"parts": {
169
"index": {
1710
"type" : "string",

src/CodeGeneration/ApiGenerator/RestSpecification/Core/clear_scroll.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html",
44
"methods": ["DELETE"],
55
"url": {
6-
"path": "/_search/scroll",
7-
"paths": [ "/_search/scroll"],
8-
"deprecated_paths" : [
9-
{
10-
"version" : "7.0",
11-
"path" : "/_search/scroll/{scroll_id}",
12-
"description" : "A scroll id can be quite large and should be specified as part of the body"
13-
}
14-
],
6+
"path": "/_search/scroll/{scroll_id}",
7+
"paths": ["/_search/scroll/{scroll_id}", "/_search/scroll"],
158
"parts": {
169
"scroll_id": {
1710
"type" : "list",

src/CodeGeneration/ApiGenerator/RestSpecification/Core/count.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
"methods": ["POST", "GET"],
55
"url": {
66
"path": "/_count",
7-
"paths": ["/_count", "/{index}/_count"],
8-
"deprecated_paths" : [
9-
{
10-
"version" : "7.0",
11-
"path" : "/{index}/{type}/_count",
12-
"description" : "Specifying types in urls has been deprecated"
13-
}
14-
],
7+
"paths": ["/_count", "/{index}/_count", "/{index}/{type}/_count"],
158
"parts": {
169
"index": {
1710
"type" : "list",

src/CodeGeneration/ApiGenerator/RestSpecification/Core/create.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
"methods": ["PUT","POST"],
55
"url": {
66
"path": "/{index}/_create/{id}",
7-
"paths": ["/{index}/_create/{id}"],
8-
"deprecated_paths" : [
9-
{
10-
"version" : "7.0",
11-
"path" : "/{index}/{type}/{id}/_create",
12-
"description" : "Specifying types in urls has been deprecated"
13-
}
14-
],
7+
"paths": ["/{index}/_create/{id}", "/{index}/{type}/{id}/_create"],
158
"parts": {
169
"id": {
1710
"type" : "string",

0 commit comments

Comments
 (0)