Skip to content

Commit 416e6f6

Browse files
authored
Fix missing deprecated attributes on low-level (#5120)
* Fix missing deprecated attributes on low-level Identified a bug after creating a patch and regenerating code where the low level generate code was not rendering deprecated attributes for some methods. The deduping logic handles aliases but does not handle non-aliased paths which is corrected by doing a final check to prefer the deprecated versions. Additional: - Updated the version of Spectre.Console - Fixed breaking change from Spectre.Console * Apply code review feedback
1 parent c9848a1 commit 416e6f6

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/ApiGenerator/ApiGenerator.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="CsQuery.Core" Version="2.0.1" />
1616
<!-- https://github.com/toddams/RazorLight/issues/172 -->
1717
<PackageReference Include="RazorLight.Unofficial" Version="2.0.0-beta1.3" />
18-
<PackageReference Include="Spectre.Console" Version="0.27.1-preview.0.8" />
18+
<PackageReference Include="Spectre.Console" Version="0.30.0" />
1919
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20371.2" />
2020
<!--<PackageReference Include="RazorLight" Version="2.0.0-beta1" />-->
2121
</ItemGroup>

src/ApiGenerator/Domain/Specification/UrlInformation.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System;
56
using System.Collections.Generic;
67
using System.Linq;
78
using Newtonsoft.Json;
@@ -50,7 +51,7 @@ public IReadOnlyCollection<UrlPath> PathsWithDeprecations
5051
// PUT /{index}/_mapping/{type}
5152
// PUT /{index}/{type}/_mappings
5253
//
53-
//The following routine dedups these occasions and prefers either the cononical path
54+
//The following routine dedups these occasions and prefers either the canonical path
5455
//or the first duplicate deprecated path
5556

5657
var canonicalPartNameLookup = paths.Select(path => new HashSet<string>(path.Parts.Select(p => p.Name))).ToList();
@@ -64,10 +65,29 @@ public IReadOnlyCollection<UrlPath> PathsWithDeprecations
6465
.Where(grouped => !canonicalPartNameLookup.Any(set => set.SetEquals(grouped.Key)))
6566
.Select(grouped => grouped.First().deprecatedPath);
6667

67-
6868
_pathsWithDeprecation = paths
6969
.Concat(withoutDeprecatedAliases.Select(p => new UrlPath(p, OriginalParts, Paths)))
7070
.ToList();
71+
72+
// now, check for and prefer deprecated URLs
73+
74+
var finalPathsWithDeprecations = new List<UrlPath>(_pathsWithDeprecation.Count);
75+
76+
foreach (var path in _pathsWithDeprecation)
77+
{
78+
if (path.Deprecation is null &&
79+
DeprecatedPaths.SingleOrDefault(p => p.Path.Equals(path.Path, StringComparison.OrdinalIgnoreCase)) is { } match)
80+
{
81+
finalPathsWithDeprecations.Add(new UrlPath(match, OriginalParts, Paths));
82+
}
83+
else
84+
{
85+
finalPathsWithDeprecations.Add(path);
86+
}
87+
}
88+
89+
_pathsWithDeprecation = finalPathsWithDeprecations;
90+
7191
return _pathsWithDeprecation;
7292
}
7393
}

src/ApiGenerator/Program.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
// See the LICENSE file in the project root for more information
44

55
using System;
6-
using System.CommandLine;
7-
using System.CommandLine.DragonFruit;
8-
using System.CommandLine.Invocation;
9-
using System.IO;
106
using System.Linq;
117
using System.Threading;
128
using System.Threading.Tasks;
@@ -21,8 +17,6 @@ public static class Program
2117
{
2218
private static bool Interactive { get; set; } = false;
2319

24-
public static Style HeaderStyle { get; } = new Style(Color.White, Color.Chartreuse4);
25-
2620
/// <summary>
2721
/// A main function can also take <see cref="CancellationToken"/> which is hooked up to support termination (e.g CTRL+C)
2822
/// </summary>
@@ -99,7 +93,7 @@ private static async Task<int> Generate(bool download, string branch, bool inclu
9993
Console.WriteLine();
10094
AnsiConsole.Render(
10195
new Panel(grid)
102-
.Header(new PanelHeader(" Elasticsearch .NET client API generator ", HeaderStyle, Justify.Left))
96+
.Header(new PanelHeader("[b white on chartreuse4] Elasticsearch .NET client API generator [/]", Justify.Left))
10397
);
10498
Console.WriteLine();
10599

0 commit comments

Comments
 (0)