From 9765459691ae5e9ca70413df327b1319e9fb3c16 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 25 Nov 2020 14:57:06 +0000 Subject: [PATCH 1/2] 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 --- src/ApiGenerator/ApiGenerator.csproj | 2 +- .../Domain/Specification/UrlInformation.cs | 18 ++++++++++++++++-- src/ApiGenerator/Program.cs | 8 +------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/ApiGenerator/ApiGenerator.csproj b/src/ApiGenerator/ApiGenerator.csproj index a595ed00bb6..9d3eb5100b0 100644 --- a/src/ApiGenerator/ApiGenerator.csproj +++ b/src/ApiGenerator/ApiGenerator.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/ApiGenerator/Domain/Specification/UrlInformation.cs b/src/ApiGenerator/Domain/Specification/UrlInformation.cs index ee3fc07404a..b2e4a0c1d3f 100644 --- a/src/ApiGenerator/Domain/Specification/UrlInformation.cs +++ b/src/ApiGenerator/Domain/Specification/UrlInformation.cs @@ -2,6 +2,7 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; @@ -50,7 +51,7 @@ public IReadOnlyCollection PathsWithDeprecations // PUT /{index}/_mapping/{type} // PUT /{index}/{type}/_mappings // - //The following routine dedups these occasions and prefers either the cononical path + //The following routine dedups these occasions and prefers either the canonical path //or the first duplicate deprecated path var canonicalPartNameLookup = paths.Select(path => new HashSet(path.Parts.Select(p => p.Name))).ToList(); @@ -64,10 +65,23 @@ public IReadOnlyCollection PathsWithDeprecations .Where(grouped => !canonicalPartNameLookup.Any(set => set.SetEquals(grouped.Key))) .Select(grouped => grouped.First().deprecatedPath); - _pathsWithDeprecation = paths .Concat(withoutDeprecatedAliases.Select(p => new UrlPath(p, OriginalParts, Paths))) .ToList(); + + // now, check for and prefer deprecated URLs + + foreach (var path in _pathsWithDeprecation.Where(p => p.Deprecation is null).ToArray()) + { + var dpMatch = DeprecatedPaths.SingleOrDefault(p => p.Path.Equals(path.Path, StringComparison.OrdinalIgnoreCase)); + + if (dpMatch is object) + { + _pathsWithDeprecation.Remove(path); + _pathsWithDeprecation.Add(new UrlPath(dpMatch, OriginalParts, Paths)); + } + } + return _pathsWithDeprecation; } } diff --git a/src/ApiGenerator/Program.cs b/src/ApiGenerator/Program.cs index 3f0604915db..bc4b0a46eb9 100644 --- a/src/ApiGenerator/Program.cs +++ b/src/ApiGenerator/Program.cs @@ -3,10 +3,6 @@ // See the LICENSE file in the project root for more information using System; -using System.CommandLine; -using System.CommandLine.DragonFruit; -using System.CommandLine.Invocation; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -21,8 +17,6 @@ public static class Program { private static bool Interactive { get; set; } = false; - public static Style HeaderStyle { get; } = new Style(Color.White, Color.Chartreuse4); - /// /// A main function can also take which is hooked up to support termination (e.g CTRL+C) /// @@ -99,7 +93,7 @@ private static async Task Generate(bool download, string branch, bool inclu Console.WriteLine(); AnsiConsole.Render( new Panel(grid) - .Header(new PanelHeader(" Elasticsearch .NET client API generator ", HeaderStyle, Justify.Left)) + .Header(new PanelHeader("[b white on chartreuse4] Elasticsearch .NET client API generator [/]", Justify.Left)) ); Console.WriteLine(); From 8ec693aebc127208849ef705662ed20e550616d6 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 26 Nov 2020 10:35:14 +0000 Subject: [PATCH 2/2] Apply code review feedback --- .../Domain/Specification/UrlInformation.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ApiGenerator/Domain/Specification/UrlInformation.cs b/src/ApiGenerator/Domain/Specification/UrlInformation.cs index b2e4a0c1d3f..fda5ce279ae 100644 --- a/src/ApiGenerator/Domain/Specification/UrlInformation.cs +++ b/src/ApiGenerator/Domain/Specification/UrlInformation.cs @@ -71,17 +71,23 @@ public IReadOnlyCollection PathsWithDeprecations // now, check for and prefer deprecated URLs - foreach (var path in _pathsWithDeprecation.Where(p => p.Deprecation is null).ToArray()) + var finalPathsWithDeprecations = new List(_pathsWithDeprecation.Count); + + foreach (var path in _pathsWithDeprecation) { - var dpMatch = DeprecatedPaths.SingleOrDefault(p => p.Path.Equals(path.Path, StringComparison.OrdinalIgnoreCase)); - - if (dpMatch is object) + if (path.Deprecation is null && + DeprecatedPaths.SingleOrDefault(p => p.Path.Equals(path.Path, StringComparison.OrdinalIgnoreCase)) is { } match) + { + finalPathsWithDeprecations.Add(new UrlPath(match, OriginalParts, Paths)); + } + else { - _pathsWithDeprecation.Remove(path); - _pathsWithDeprecation.Add(new UrlPath(dpMatch, OriginalParts, Paths)); + finalPathsWithDeprecations.Add(path); } } + _pathsWithDeprecation = finalPathsWithDeprecations; + return _pathsWithDeprecation; } }