From 045cd9ddbef40646aa4e3046891cbdfe1106df4a Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Fri, 27 Mar 2020 16:55:29 +1000 Subject: [PATCH] Fix API generator (#4456) (#4514) This commit fixes the API generator: 1. The collection of high level endpoints were being used in some of the low level generators 2. High level endpoints excluded need to be compared to the list by filename Co-authored-by: Stuart Cam (cherry-picked from commit 04ed38b09519a19093d2fd2f467c2e6513fbfcc9) --- src/ApiGenerator/Domain/RestApiSpec.cs | 4 ++-- .../Generator/Razor/LowLevelClientImplementationGenerator.cs | 2 +- .../Generator/Razor/RequestParametersGenerator.cs | 2 +- .../Client/Implementation/ElasticLowLevelClient.cshtml | 4 ++-- .../LowLevel/Client/Interface/IElasticLowLevelClient.cshtml | 2 +- src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ApiGenerator/Domain/RestApiSpec.cs b/src/ApiGenerator/Domain/RestApiSpec.cs index 1f5bb02473e..06949bc0d79 100644 --- a/src/ApiGenerator/Domain/RestApiSpec.cs +++ b/src/ApiGenerator/Domain/RestApiSpec.cs @@ -22,13 +22,13 @@ public class RestApiSpec public IDictionary Endpoints { get; set; } - public ImmutableSortedDictionary> EndpointsPerNamespace => + public ImmutableSortedDictionary> EndpointsPerNamespaceLowLevel => Endpoints.Values.GroupBy(e=>e.CsharpNames.Namespace) .ToImmutableSortedDictionary(kv => kv.Key, kv => kv.ToList().AsReadOnly()); public ImmutableSortedDictionary> EndpointsPerNamespaceHighLevel => Endpoints.Values - .Where(v => !CodeConfiguration.IgnoredApisHighLevel.Contains(v.Name)) + .Where(v => !CodeConfiguration.IgnoredApisHighLevel.Contains(v.FileName)) .GroupBy(e => e.CsharpNames.Namespace) .ToImmutableSortedDictionary(kv => kv.Key, kv => kv.ToList().AsReadOnly()); diff --git a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs index b057dd68e5e..c1d95d1e775 100644 --- a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs +++ b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs @@ -22,7 +22,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar) var target = GeneratorLocations.LowLevel($"ElasticLowLevelClient.{CsharpNames.RootNamespace}.cs"); await DoRazor(spec, view, target); - var namespaced = spec.EndpointsPerNamespaceHighLevel.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList(); + var namespaced = spec.EndpointsPerNamespaceLowLevel.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList(); var namespacedView = ViewLocations.LowLevel("Client", "Implementation", "ElasticLowLevelClient.Namespace.cshtml"); await DoRazorDependantFiles(progressBar, namespaced, namespacedView, kv => kv.Key, id => GeneratorLocations.LowLevel($"ElasticLowLevelClient.{id}.cs")); diff --git a/src/ApiGenerator/Generator/Razor/RequestParametersGenerator.cs b/src/ApiGenerator/Generator/Razor/RequestParametersGenerator.cs index 6773548b825..205aa73edd5 100644 --- a/src/ApiGenerator/Generator/Razor/RequestParametersGenerator.cs +++ b/src/ApiGenerator/Generator/Razor/RequestParametersGenerator.cs @@ -20,7 +20,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar) var view = ViewLocations.LowLevel("RequestParameters", "RequestParameters.cshtml"); string Target(string id) => GeneratorLocations.LowLevel("Api", "RequestParameters", $"RequestParameters.{id}.cs"); - var namespaced = spec.EndpointsPerNamespaceHighLevel.ToList(); + var namespaced = spec.EndpointsPerNamespaceLowLevel.ToList(); await DoRazorDependantFiles(progressBar, namespaced, view, kv => kv.Key, id => Target(id)); } } diff --git a/src/ApiGenerator/Views/LowLevel/Client/Implementation/ElasticLowLevelClient.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Implementation/ElasticLowLevelClient.cshtml index a19a419166e..f2331c01e88 100644 --- a/src/ApiGenerator/Views/LowLevel/Client/Implementation/ElasticLowLevelClient.cshtml +++ b/src/ApiGenerator/Views/LowLevel/Client/Implementation/ElasticLowLevelClient.cshtml @@ -24,7 +24,7 @@ using static Elasticsearch.Net.HttpMethod; @{ RestApiSpec model = Model; - var namespaces = model.EndpointsPerNamespace.Keys.Where(k => k != CsharpNames.RootNamespace); + var namespaces = model.EndpointsPerNamespaceLowLevel.Keys.Where(k => k != CsharpNames.RootNamespace); // ReSharper disable InterpolatedStringExpressionIsNotIFormattable // ReSharper disable RedundantExtendsListEntry @@ -55,7 +55,7 @@ namespace Elasticsearch.Net - foreach (var kv in model.EndpointsPerNamespace) + foreach (var kv in model.EndpointsPerNamespaceLowLevel) { if (kv.Key != CsharpNames.RootNamespace) { diff --git a/src/ApiGenerator/Views/LowLevel/Client/Interface/IElasticLowLevelClient.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Interface/IElasticLowLevelClient.cshtml index c1f9a747149..ed2d019ca4e 100644 --- a/src/ApiGenerator/Views/LowLevel/Client/Interface/IElasticLowLevelClient.cshtml +++ b/src/ApiGenerator/Views/LowLevel/Client/Interface/IElasticLowLevelClient.cshtml @@ -23,7 +23,7 @@ namespace Elasticsearch.Net /// public partial interface IElasticLowLevelClient { - @foreach(var kv in Model.EndpointsPerNamespace) + @foreach(var kv in Model.EndpointsPerNamespaceLowLevel) { if (kv.Key != CsharpNames.RootNamespace) { diff --git a/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml index b80f3a3d215..ff8546c5dba 100644 --- a/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml +++ b/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml @@ -3,7 +3,7 @@ @using ApiGenerator.Domain @using ApiGenerator.Domain.Code @inherits ApiGenerator.CodeTemplatePage -@foreach(var kv in Model.EndpointsPerNamespace) +@foreach(var kv in Model.EndpointsPerNamespaceLowLevel) { if (kv.Key != CsharpNames.RootNamespace) {