Skip to content

Commit

Permalink
Fix API generator (#4456) (#4514)
Browse files Browse the repository at this point in the history
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 <stuart.cam@elastic.co>

(cherry-picked from commit 04ed38b)
  • Loading branch information
russcam committed Mar 27, 2020
1 parent 625c13e commit e791310
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ApiGenerator/Domain/RestApiSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class RestApiSpec

public IDictionary<string, ApiEndpoint> Endpoints { get; set; }

public ImmutableSortedDictionary<string, ReadOnlyCollection<ApiEndpoint>> EndpointsPerNamespace =>
public ImmutableSortedDictionary<string, ReadOnlyCollection<ApiEndpoint>> EndpointsPerNamespaceLowLevel =>
Endpoints.Values.GroupBy(e=>e.CsharpNames.Namespace)
.ToImmutableSortedDictionary(kv => kv.Key, kv => kv.ToList().AsReadOnly());

public ImmutableSortedDictionary<string, ReadOnlyCollection<ApiEndpoint>> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
<text>
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
// ReSharper disable RedundantExtendsListEntry
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace Elasticsearch.Net
</text>


foreach (var kv in model.EndpointsPerNamespace)
foreach (var kv in model.EndpointsPerNamespaceLowLevel)
{
if (kv.Key != CsharpNames.RootNamespace)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Elasticsearch.Net
///</summary>
public partial interface IElasticLowLevelClient
{
@foreach(var kv in Model.EndpointsPerNamespace)
@foreach(var kv in Model.EndpointsPerNamespaceLowLevel)
{
if (kv.Key != CsharpNames.RootNamespace)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@using ApiGenerator.Domain
@using ApiGenerator.Domain.Code
@inherits ApiGenerator.CodeTemplatePage<RestApiSpec>
@foreach(var kv in Model.EndpointsPerNamespace)
@foreach(var kv in Model.EndpointsPerNamespaceLowLevel)
{
if (kv.Key != CsharpNames.RootNamespace)
{
Expand Down

0 comments on commit e791310

Please sign in to comment.