Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ namespace ApiGenerator.Configuration.Overrides
{
public class GlobalOverrides : EndpointOverridesBase
{
public IDictionary<string, Dictionary<string, string>> ObsoleteEnumMembers { get; set; } = new Dictionary<string, Dictionary<string, string>>
{
{
"NodesStatsIndexMetric",
new Dictionary<string, string> { { "suggest", "As of 5.0 this option always returned an empty object in the response" } }
},
{
"IndicesStatsMetric",
new Dictionary<string, string> { { "suggest", "Suggest stats have folded under the search stats, this alias will be removed" } }
}
};
public IDictionary<string, Dictionary<string, string>> ObsoleteEnumMembers { get; set; } = new Dictionary<string, Dictionary<string, string>>();

public override IDictionary<string, string> ObsoleteQueryStringParams { get; set; } = new Dictionary<string, string>
{
Expand Down
13 changes: 11 additions & 2 deletions src/CodeGeneration/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ private static void PatchOfficialSpec(JObject original, string jsonFile)
});

if (pathsOverride != null) original.SelectToken("*.url.paths").Replace(pathsOverride);
}

void ReplaceOptions(string path)
{
var optionsOverrides = patchedJson.SelectToken(path);
if (optionsOverrides != null)
original.SelectToken(path).Replace(optionsOverrides);
}

ReplaceOptions("*.url.parts.metric.options");
ReplaceOptions("*.url.parts.index_metric.options");
}
}
}
}
11 changes: 6 additions & 5 deletions src/CodeGeneration/ApiGenerator/Generator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ApiGenerator.Domain.Specification;
Expand All @@ -15,20 +16,20 @@ public class ApiGenerator
{
public static List<string> Warnings { get; private set; }

public static void Generate(string downloadBranch, params string[] folders)
public static async Task Generate(string downloadBranch, params string[] folders)
{
Warnings = new List<string>();
var spec = CreateRestApiSpecModel(downloadBranch, folders);
var generators = new List<RazorGeneratorBase>
{

//low level client
new LowLevelClientInterfaceGenerator(),
new LowLevelClientImplementationGenerator(),
new RequestParametersGenerator(),
new EnumsGenerator(),


//high level client
new HighLevelClientInterfaceGenerator(),
new HighLevelClientImplementationGenerator(),
Expand All @@ -42,7 +43,7 @@ public static void Generate(string downloadBranch, params string[] folders)
foreach (var generator in generators)
{
pbar.Message = "Generating " + generator.Title;
generator.Generate(spec, pbar);
await generator.Generate(spec, pbar);
pbar.Tick("Generated " + generator.Title);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class ApiUrlsLookupsGenerator : RazorGeneratorBase
{
public override string Title => "NEST static url lookups";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.HighLevel("Requests", "ApiUrlsLookup.cshtml");
var target = GeneratorLocations.HighLevel("_Generated", "ApiUrlsLookup.generated.cs");
DoRazor(spec, view, target);

await DoRazor(spec, view, target);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
using System.Linq;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class DescriptorsGenerator : RazorGeneratorBase
{
public override string Title => "NEST descriptors";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.HighLevel("Descriptors", "RequestDescriptorBase.cshtml");
var target = GeneratorLocations.HighLevel("Descriptors.cs");
DoRazor(spec, view, target);
await DoRazor(spec, view, target);

var dependantView = ViewLocations.HighLevel("Descriptors", "Descriptors.cshtml");
string Target(string id) => GeneratorLocations.HighLevel($"Descriptors.{id}.cs");
var namespaced = spec.EndpointsPerNamespace.ToList();
DoRazorDependantFiles(progressBar, namespaced, dependantView, kv => kv.Key, id => Target(id));
await DoRazorDependantFiles(progressBar, namespaced, dependantView, kv => kv.Key, id => Target(id));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class EnumsGenerator : RazorGeneratorBase
{
public override string Title => "Elasticsearch.Net enums";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.LowLevel("Enums.Generated.cshtml");
var target = GeneratorLocations.LowLevel("Api", "Enums.Generated.cs");
DoRazor(spec, view, target);

await DoRazor(spec, view, target);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
using System.Linq;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ApiGenerator.Domain.Code;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class HighLevelClientImplementationGenerator : RazorGeneratorBase
{
public override string Title => "NEST client implementation";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.HighLevel("Client", "Implementation", "ElasticClient.cshtml");
var target = GeneratorLocations.HighLevel($"ElasticClient.{CsharpNames.RootNamespace}.cs");
DoRazor(spec, view, target);
await DoRazor(spec, view, target);

string Target(string id) => GeneratorLocations.HighLevel($"ElasticClient.{id}.cs");

var namespaced = spec.EndpointsPerNamespace.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList();
var dependantView = ViewLocations.HighLevel("Client", "Implementation", "ElasticClient.Namespace.cshtml");
DoRazorDependantFiles(progressBar, namespaced, dependantView, kv => kv.Key, id => Target(id));
await DoRazorDependantFiles(progressBar, namespaced, dependantView, kv => kv.Key, id => Target(id));

}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class HighLevelClientInterfaceGenerator : RazorGeneratorBase
{
public override string Title => "NEST client interface";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.HighLevel("Client", "Interface", "IElasticClient.cshtml");
var target = GeneratorLocations.HighLevel("IElasticClient.Generated.cs");

DoRazor(spec, view, target);


await DoRazor(spec, view, target);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using System.Linq;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ApiGenerator.Domain.Code;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor {
namespace ApiGenerator.Generator.Razor
{
public class LowLevelClientImplementationGenerator : RazorGeneratorBase
{
public override string Title { get; } = "Elasticsearch.Net client implementation";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.LowLevel("Client", "Implementation", "ElasticLowLevelClient.cshtml");
var target = GeneratorLocations.LowLevel($"ElasticLowLevelClient.{CsharpNames.RootNamespace}.cs");
DoRazor(spec, view, target);
await DoRazor(spec, view, target);

var namespaced = spec.EndpointsPerNamespace.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList();
var namespacedView = ViewLocations.LowLevel("Client", "Implementation", "ElasticLowLevelClient.Namespace.cshtml");
DoRazorDependantFiles(progressBar, namespaced, namespacedView, kv => kv.Key, id => GeneratorLocations.LowLevel($"ElasticLowLevelClient.{id}.cs"));
await DoRazorDependantFiles(progressBar, namespaced, namespacedView, kv => kv.Key,
id => GeneratorLocations.LowLevel($"ElasticLowLevelClient.{id}.cs"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class LowLevelClientInterfaceGenerator : RazorGeneratorBase
{
public override string Title { get; } = "Elasticsearch.Net client interface";
public override void Generate(RestApiSpec spec, ProgressBar progressBar)

public override async Task Generate(RestApiSpec spec, ProgressBar progressBar)
{
var view = ViewLocations.LowLevel("Client", "Interface", "IElasticLowLevelClient.cshtml");
var target = GeneratorLocations.LowLevel("IElasticLowLevelClient.Generated.cs");
DoRazor(spec, view, target);

await DoRazor(spec, view, target);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using Microsoft.CodeAnalysis;
Expand All @@ -19,13 +20,13 @@ public abstract class RazorGeneratorBase
.UseMemoryCachingProvider()
.Build();

protected void DoRazor<TModel>(TModel model, string viewLocation, string targetLocation, string cacheNameSuffix = null)
protected async Task DoRazor<TModel>(TModel model, string viewLocation, string targetLocation, string cacheNameSuffix = null)
{
try
{
var name = GetType().Name + cacheNameSuffix;
var sourceFileContents = File.ReadAllText(viewLocation);
var generated = Engine.CompileRenderStringAsync(name, sourceFileContents, model).GetAwaiter().GetResult();
var generated = await Engine.CompileRenderStringAsync(name, sourceFileContents, model);
WriteFormattedCsharpFile(targetLocation, generated);
}
catch (TemplateGenerationException e)
Expand All @@ -35,8 +36,8 @@ protected void DoRazor<TModel>(TModel model, string viewLocation, string targetL
}
}

protected void DoRazorDependantFiles<TModel>(
ProgressBar pbar, IReadOnlyCollection<TModel> items, string viewLocation,
protected async Task DoRazorDependantFiles<TModel>(
ProgressBar pbar, IReadOnlyCollection<TModel> items, string viewLocation,
Func<TModel, string> identifier, Func<string, string> target)
{
using (var c = pbar.Spawn(items.Count, "Generating namespaces", new ProgressBarOptions { ForegroundColor = ConsoleColor.Yellow }))
Expand All @@ -45,12 +46,12 @@ protected void DoRazorDependantFiles<TModel>(
{
var id = identifier(item);
var targetLocation = target(id);
DoRazor(item, viewLocation, targetLocation, id);
await DoRazor(item, viewLocation, targetLocation, id);
c.Tick($"{Title}: {id}");
}
}
}

protected static void WriteFormattedCsharpFile(string path, string contents)
{
var tree = CSharpSyntaxTree.ParseText(contents);
Expand All @@ -60,6 +61,6 @@ protected static void WriteFormattedCsharpFile(string path, string contents)
}

public abstract string Title { get; }
public abstract void Generate(RestApiSpec spec, ProgressBar progressBar);
public abstract Task Generate(RestApiSpec spec, ProgressBar progressBar);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using System.Linq;
using System.Threading.Tasks;
using ApiGenerator.Configuration;
using ApiGenerator.Domain;
using ShellProgressBar;

namespace ApiGenerator.Generator.Razor
namespace ApiGenerator.Generator.Razor
{
public class RequestParametersGenerator : RazorGeneratorBase
{
public override string Title { get; } = "Elasticsearch.Net request parameters";

public override void Generate(RestApiSpec spec, ProgressBar progressBar)
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.EndpointsPerNamespace.ToList();
DoRazorDependantFiles(progressBar, namespaced, view, kv => kv.Key, id => Target(id));
await DoRazorDependantFiles(progressBar, namespaced, view, kv => kv.Key, id => Target(id));
}
}
}
}
Loading