diff --git a/src/ApiGenerator/ApiGenerator.csproj b/src/ApiGenerator/ApiGenerator.csproj
index 4505f23ddf..ca6a5783b9 100644
--- a/src/ApiGenerator/ApiGenerator.csproj
+++ b/src/ApiGenerator/ApiGenerator.csproj
@@ -15,10 +15,11 @@
-
+
+
diff --git a/src/ApiGenerator/CodeTemplatePage.cs b/src/ApiGenerator/CodeTemplatePage.cs
index 7b59c684af..8b14cd1ead 100644
--- a/src/ApiGenerator/CodeTemplatePage.cs
+++ b/src/ApiGenerator/CodeTemplatePage.cs
@@ -26,17 +26,16 @@
* under the License.
*/
-using System;
using System.Threading.Tasks;
using RazorLight;
-namespace ApiGenerator
+namespace ApiGenerator
{
- /// This only exists to make the IDE tooling happy, not actually used to render the templates
- public class CodeTemplatePage : TemplatePage
- {
- public override Task ExecuteAsync() => throw new NotImplementedException();
+ public abstract class CodeTemplatePage : TemplatePage
+ {
+ protected new Task IncludeAsync(string key, object model = null)
+ => base.IncludeAsync(key.Replace('/', '.'), model);
- public Task Execute() => Task.CompletedTask;
- }
+ protected async Task IncludeGeneratorNotice() => await IncludeAsync("GeneratorNotice");
+ }
}
diff --git a/src/ApiGenerator/Configuration/ViewLocations.cs b/src/ApiGenerator/Configuration/ViewLocations.cs
index 5adfd3c46d..3339f85d1d 100644
--- a/src/ApiGenerator/Configuration/ViewLocations.cs
+++ b/src/ApiGenerator/Configuration/ViewLocations.cs
@@ -26,15 +26,12 @@
* under the License.
*/
-namespace ApiGenerator.Configuration
+namespace ApiGenerator.Configuration
{
public static class ViewLocations
{
- public static string Root { get; } = $@"{GeneratorLocations.Root}Views/";
- private static string HighLevelRoot { get; } = $@"{Root}/HighLevel/";
- public static string HighLevel(params string[] paths) => HighLevelRoot + string.Join("/", paths);
-
- private static string LowLevelRoot { get; } = $@"{Root}/LowLevel/";
- public static string LowLevel(params string[] paths) => LowLevelRoot + string.Join("/", paths);
+ public static string HighLevel(params string[] paths) => "HighLevel." + string.Join(".", paths);
+
+ public static string LowLevel(params string[] paths) => "LowLevel." + string.Join(".", paths);
}
}
diff --git a/src/ApiGenerator/Generator/Razor/ApiUrlsLookupsGenerator.cs b/src/ApiGenerator/Generator/Razor/ApiUrlsLookupsGenerator.cs
index 35189de048..c0a2fef2bd 100644
--- a/src/ApiGenerator/Generator/Razor/ApiUrlsLookupsGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/ApiUrlsLookupsGenerator.cs
@@ -43,7 +43,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.HighLevel("Requests", "ApiUrlsLookup.cshtml");
var target = GeneratorLocations.HighLevel("_Generated", "ApiUrlsLookup.generated.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
}
}
}
diff --git a/src/ApiGenerator/Generator/Razor/DescriptorsGenerator.cs b/src/ApiGenerator/Generator/Razor/DescriptorsGenerator.cs
index fa9e3f7ff8..523ea35145 100644
--- a/src/ApiGenerator/Generator/Razor/DescriptorsGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/DescriptorsGenerator.cs
@@ -48,7 +48,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.HighLevel("Descriptors", "RequestDescriptorBase.cshtml");
var target = GeneratorLocations.HighLevel("Descriptors.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
var dependantView = ViewLocations.HighLevel("Descriptors", "Descriptors.cshtml");
string Target(string id) => GeneratorLocations.HighLevel($"Descriptors.{id}.cs");
diff --git a/src/ApiGenerator/Generator/Razor/EnumsGenerator.cs b/src/ApiGenerator/Generator/Razor/EnumsGenerator.cs
index 3708c5051a..74d3c56830 100644
--- a/src/ApiGenerator/Generator/Razor/EnumsGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/EnumsGenerator.cs
@@ -43,7 +43,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.LowLevel("Enums.Generated.cshtml");
var target = GeneratorLocations.LowLevel("Api", "Enums.Generated.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
}
}
}
diff --git a/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs b/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs
index a37dc00761..eacbe058e8 100644
--- a/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/HighLevelClientImplementationGenerator.cs
@@ -49,7 +49,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.HighLevel("Client", "Implementation", "OpenSearchClient.cshtml");
var target = GeneratorLocations.HighLevel($"OpenSearchClient.{CsharpNames.RootNamespace}.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
string Target(string id) => GeneratorLocations.HighLevel($"OpenSearchClient.{id}.cs");
diff --git a/src/ApiGenerator/Generator/Razor/HighLevelClientInterfaceGenerator.cs b/src/ApiGenerator/Generator/Razor/HighLevelClientInterfaceGenerator.cs
index 9b35b9a919..b9957db2f5 100644
--- a/src/ApiGenerator/Generator/Razor/HighLevelClientInterfaceGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/HighLevelClientInterfaceGenerator.cs
@@ -43,7 +43,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.HighLevel("Client", "Interface", "IOpenSearchClient.cshtml");
var target = GeneratorLocations.HighLevel("IOpenSearchClient.Generated.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
}
}
}
diff --git a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs
index bd41fac4b8..da174b21db 100644
--- a/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/LowLevelClientImplementationGenerator.cs
@@ -49,7 +49,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.LowLevel("Client", "Implementation", "OpenSearchLowLevelClient.cshtml");
var target = GeneratorLocations.LowLevel($"OpenSearchLowLevelClient.{CsharpNames.RootNamespace}.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
var namespaced = spec.EndpointsPerNamespaceLowLevel.Where(kv => kv.Key != CsharpNames.RootNamespace).ToList();
var namespacedView = ViewLocations.LowLevel("Client", "Implementation", "OpenSearchLowLevelClient.Namespace.cshtml");
diff --git a/src/ApiGenerator/Generator/Razor/LowLevelClientInterfaceGenerator.cs b/src/ApiGenerator/Generator/Razor/LowLevelClientInterfaceGenerator.cs
index f1d31074ce..6340b66b35 100644
--- a/src/ApiGenerator/Generator/Razor/LowLevelClientInterfaceGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/LowLevelClientInterfaceGenerator.cs
@@ -43,7 +43,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.LowLevel("Client", "Interface", "IOpenSearchLowLevelClient.cshtml");
var target = GeneratorLocations.LowLevel("IOpenSearchLowLevelClient.Generated.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
}
}
}
diff --git a/src/ApiGenerator/Generator/Razor/RazorGeneratorBase.cs b/src/ApiGenerator/Generator/Razor/RazorGeneratorBase.cs
index e24e7803ad..8a4ef0200a 100644
--- a/src/ApiGenerator/Generator/Razor/RazorGeneratorBase.cs
+++ b/src/ApiGenerator/Generator/Razor/RazorGeneratorBase.cs
@@ -45,18 +45,18 @@ namespace ApiGenerator.Generator.Razor
public abstract class RazorGeneratorBase
{
private static readonly RazorLightEngine Engine = new RazorLightEngineBuilder()
- .UseProject(new FileSystemRazorProject(Path.GetFullPath(ViewLocations.Root)))
- .UseMemoryCachingProvider()
+ .UseProject(new EmbeddedRazorProject(typeof(CodeTemplatePage<>).Assembly, "ApiGenerator.Views"))
+ .SetOperatingAssembly(typeof(CodeTemplatePage<>).Assembly)
+ .UseMemoryCachingProvider()
+ .EnableDebugMode()
.Build();
- protected async Task DoRazor(TModel model, string viewLocation, string targetLocation, string cacheNameSuffix, CancellationToken token)
+ protected async Task DoRazor(TModel model, string viewLocation, string targetLocation, CancellationToken token)
{
try
{
- var name = GetType().Name + cacheNameSuffix;
- var sourceFileContents = await File.ReadAllTextAsync(viewLocation, token);
token.ThrowIfCancellationRequested();
- var generated = await Engine.CompileRenderStringAsync(name, sourceFileContents, model);
+ var generated = await Engine.CompileRenderAsync(viewLocation, model);
WriteFormattedCsharpFile(targetLocation, generated);
}
catch (TemplateGenerationException e)
@@ -82,7 +82,7 @@ CancellationToken token
{
var id = identifier(item);
var targetLocation = target(id);
- await DoRazor(item, viewLocation, targetLocation, id, token);
+ await DoRazor(item, viewLocation, targetLocation, token);
c.Tick($"{Title}: {id}");
}
}
diff --git a/src/ApiGenerator/Generator/Razor/RequestsGenerator.cs b/src/ApiGenerator/Generator/Razor/RequestsGenerator.cs
index c7aa78b624..60ca992f73 100644
--- a/src/ApiGenerator/Generator/Razor/RequestsGenerator.cs
+++ b/src/ApiGenerator/Generator/Razor/RequestsGenerator.cs
@@ -48,7 +48,7 @@ public override async Task Generate(RestApiSpec spec, ProgressBar progressBar, C
var view = ViewLocations.HighLevel("Requests", "PlainRequestBase.cshtml");
var target = GeneratorLocations.HighLevel("Requests.cs");
- await DoRazor(spec, view, target, null, token);
+ await DoRazor(spec, view, target, token);
var dependantView = ViewLocations.HighLevel("Requests", "Requests.cshtml");
string Target(string id) => GeneratorLocations.HighLevel($"Requests.{id}.cs");
diff --git a/src/ApiGenerator/Program.cs b/src/ApiGenerator/Program.cs
index 6accfaf68e..4a219ddf11 100644
--- a/src/ApiGenerator/Program.cs
+++ b/src/ApiGenerator/Program.cs
@@ -77,7 +77,7 @@ private static async Task Main(
AnsiConsole.WriteLine();
AnsiConsole.Write(new Rule("[b white on darkred] Exception [/]").LeftJustified());
AnsiConsole.WriteLine();
- AnsiConsole.WriteException(ex);
+ AnsiConsole.WriteException(ex, ExceptionFormats.ShowLinks);
return 1;
}
return 0;
diff --git a/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethod.cshtml b/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethod.cshtml
index 5847b6ee46..10b88e61eb 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethod.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethod.cshtml
@@ -2,19 +2,17 @@
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage
@{
- FluentSyntaxBase syntax = Model.Syntax;
-
- var method = !Model.Async ? syntax.MethodName : string.Format("{0}Async", syntax.MethodName);
+ var method = !Model.Async ? Model.Syntax.MethodName : string.Format("{0}Async", Model.Syntax.MethodName);
var asyncKeyword = Model.Syntax.InterfaceResponse && Model.Async ? "async " : String.Empty;
var awaitKeyWord = Model.Syntax.InterfaceResponse && Model.Async ? "await ": string.Empty;
var configureAwait = Model.Syntax.InterfaceResponse && Model.Async ? ".ConfigureAwait(false)" : String.Empty;
- var requestMethodGenerics = syntax.RequestMethodGenerics;
- var descriptor = syntax.DescriptorName;
- var selectorArgs = syntax.SelectorArguments();
- var selectorChained = syntax.SelectorChainedDefaults();
+ var requestMethodGenerics = Model.Syntax.RequestMethodGenerics;
+ var descriptor = Model.Syntax.DescriptorName;
+ var selectorArgs = Model.Syntax.SelectorArguments();
+ var selectorChained = Model.Syntax.SelectorChainedDefaults();
var cancellationToken = !Model.Async ? string.Empty : ", ct";
}
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", syntax); }
+@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", Model.Syntax); }
public @(asyncKeyword)@{ await IncludeAsync("HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml", Model);} @Raw("=>")
@(awaitKeyWord)@(method)@(Raw(requestMethodGenerics))(selector.InvokeOrDefault(new @(Raw(descriptor))(@Raw(selectorArgs))@(@selectorChained))@cancellationToken)@Raw(configureAwait);
diff --git a/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml b/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml
index 547c087257..fa7873f2d9 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml
@@ -1,16 +1,14 @@
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage
@{
- FluentSyntaxBase syntax = Model.Syntax;
-
- var response = !Model.Async ? syntax.ResponseName : string.Format("Task<{0}>", syntax.ResponseName);
- var method = !Model.Async ? syntax.MethodName : string.Format("{0}Async", syntax.MethodName);
+ var response = !Model.Async ? Model.Syntax.ResponseName : string.Format("Task<{0}>", Model.Syntax.ResponseName);
+ var method = !Model.Async ? Model.Syntax.MethodName : string.Format("{0}Async", Model.Syntax.MethodName);
- var methodGenerics = syntax.MethodGenerics;
- var descriptorArgs = syntax.DescriptorArguments();
- var selector = syntax.Selector;
- var optionalSelector = syntax.OptionalSelectorSuffix;
- var whereClause = syntax.GenericWhereClause;
+ var methodGenerics = Model.Syntax.MethodGenerics;
+ var descriptorArgs = Model.Syntax.DescriptorArguments();
+ var selector = Model.Syntax.Selector;
+ var optionalSelector = Model.Syntax.OptionalSelectorSuffix;
+ var whereClause = Model.Syntax.GenericWhereClause;
var cancellationToken = !Model.Async ? string.Empty : ", CancellationToken ct = default";
}
@Raw(response) @(method)@(Raw(methodGenerics))(@(Raw(descriptorArgs))@(Raw(selector)) selector@(optionalSelector)@(cancellationToken))@whereClause
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Implementation/MethodImplementation.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Implementation/MethodImplementation.cshtml
index 978a9b2a3e..6469fa22f1 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Implementation/MethodImplementation.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Implementation/MethodImplementation.cshtml
@@ -3,18 +3,17 @@
@using HighLevelModel = ApiGenerator.Domain.Code.HighLevel.Methods.HighLevelModel
@inherits CodeTemplatePage
@{
- HighLevelModel model = Model;
- var fluentPath = "HighLevel/Client/FluentSyntax/FluentMethod.cshtml";
- var initializerPath = "HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml";
+ const string fluentPath = "HighLevel/Client/FluentSyntax/FluentMethod.cshtml";
+ const string initializerPath = "HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml";
}
-@{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.Fluent, async: false)); }
-@{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.Fluent, async: true)); }
-@if (model.FluentBound != null)
+@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: false)); }
+@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: true)); }
+@if (Model.FluentBound != null)
{
- @{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.FluentBound, async: false)); }
- @{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.FluentBound, async: true)); }
+ @{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: false)); }
+ @{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: true)); }
}
-@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(model.Initializer, async: false)); }
-@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(model.Initializer, async: true)); }
+@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: false)); }
+@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: true)); }
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.Namespace.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.Namespace.cshtml
index 31934d8da9..7073b4271b 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.Namespace.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.Namespace.cshtml
@@ -5,30 +5,28 @@
@using ApiGenerator.Domain.Specification
@inherits ApiGenerator.CodeTemplatePage>>
@{
- KeyValuePair> model = Model;
- string ns = model.Key;
- var endpoints = model.Value;
+ var (ns, endpoints) = Model;
}
-@{ await IncludeAsync("GeneratorNotice.cshtml", model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Threading;
using System.Threading.Tasks;
-using OpenSearch.Net.@(CsharpNames.ApiNamespace).@(ns)@(CsharpNames.ApiNamespaceSuffix);
+using OpenSearch.Net.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiNamespaceSuffix);
// ReSharper disable once CheckNamespace
// ReSharper disable RedundantTypeArgumentsOfMethod
-namespace OpenSearch.Client.@(CsharpNames.ApiNamespace).@(ns)@(CsharpNames.ApiNamespaceSuffix)
+namespace OpenSearch.Client.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiNamespaceSuffix)
{
///
- /// @(ns.SplitPascalCase()) APIs.
+ /// @ns.SplitPascalCase() APIs.
/// Not intended to be instantiated directly. Use the property
/// on .
///
///
- public class @(CsharpNames.HighLevelClientNamespacePrefix)@(model.Key)@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
+ public class @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
{
- internal @(CsharpNames.HighLevelClientNamespacePrefix)@(model.Key)@(CsharpNames.ClientNamespaceSuffix)(OpenSearchClient client) : base(client) {}
+ internal @(CsharpNames.HighLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix)(OpenSearchClient client) : base(client) {}
@foreach(var e in endpoints)
{
await IncludeAsync("HighLevel/Client/Implementation/MethodImplementation.cshtml", e.HighLevelModel);
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.cshtml
index 1fa8f03b90..5b65ac4ba7 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Implementation/OpenSearchClient.cshtml
@@ -3,7 +3,7 @@
@using ApiGenerator
@using ApiGenerator.Domain.Code
@inherits CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Threading;
@@ -12,8 +12,7 @@ using OpenSearch.Client;
@{ await IncludeAsync("HighLevel/Client/Usings.cshtml", Model);}
@{
- RestApiSpec model = Model;
- var namespaces = model.EndpointsPerNamespaceHighLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
+ var namespaces = Model.EndpointsPerNamespaceHighLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
// ReSharper disable RedundantTypeArgumentsOfMethod
namespace OpenSearch.Client
@@ -44,7 +43,7 @@ namespace OpenSearch.Client
- foreach (var kv in model.EndpointsPerNamespaceHighLevel)
+ foreach (var kv in Model.EndpointsPerNamespaceHighLevel)
{
if (kv.Key != CsharpNames.RootNamespace)
{
diff --git a/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml b/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml
index ea70731bcc..0526bad6b1 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethod.cshtml
@@ -2,11 +2,9 @@
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage
@{
- InitializerMethod syntax = Model.Syntax;
-
- var dispatchMethod = !Model.Async ? syntax.DispatchMethod : string.Format("{0}Async", syntax.DispatchMethod);
- var dispatchGenerics = syntax.DispatchGenerics;
- var dispatchParameters = syntax.DispatchParameters;
+ var dispatchMethod = !Model.Async ? Model.Syntax.DispatchMethod : string.Format("{0}Async", Model.Syntax.DispatchMethod);
+ var dispatchGenerics = Model.Syntax.DispatchGenerics;
+ var dispatchParameters = Model.Syntax.DispatchParameters;
var asyncKeyword = Model.Syntax.InterfaceResponse && Model.Async ? "async " : String.Empty;
var awaitKeyWord = Model.Syntax.InterfaceResponse && Model.Async ? "await ": string.Empty;
var configureAwait = Model.Syntax.InterfaceResponse && Model.Async ? ".ConfigureAwait(false)" : String.Empty;
@@ -15,7 +13,7 @@
dispatchParameters += ", ct";
}
}
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", syntax); }
+@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", Model.Syntax); }
public @Raw(asyncKeyword)@{ await IncludeAsync("HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml", Model); } @Raw("=>")
@(awaitKeyWord)@(dispatchMethod)@(Raw(dispatchGenerics))(@Raw(dispatchParameters))@Raw(configureAwait);
diff --git a/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml b/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml
index aaf70f0c83..f93edc5877 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml
@@ -1,17 +1,15 @@
@using ApiGenerator.Domain.Code.HighLevel.Methods
@inherits ApiGenerator.CodeTemplatePage
@{
- InitializerMethod syntax = Model.Syntax;
-
- var response = !Model.Async ? syntax.ResponseName : string.Format("Task<{0}>", syntax.ResponseName);
- var method = !Model.Async ? syntax.MethodName : string.Format("{0}Async", syntax.MethodName);
- var requestMethodGenerics = syntax.MethodGenerics;
+ var response = !Model.Async ? Model.Syntax.ResponseName : string.Format("Task<{0}>", Model.Syntax.ResponseName);
+ var method = !Model.Async ? Model.Syntax.MethodName : string.Format("{0}Async", Model.Syntax.MethodName);
+ var requestMethodGenerics = Model.Syntax.MethodGenerics;
- var methodsArgs = string.Format("{0} request", syntax.ArgumentType);
+ var methodsArgs = string.Format("{0} request", Model.Syntax.ArgumentType);
if (Model.Async)
{
methodsArgs += ", CancellationToken ct = default";
}
- var whereClause = syntax.GenericWhereClause;
+ var whereClause = Model.Syntax.GenericWhereClause;
}
@Raw(response) @(method)@(Raw(requestMethodGenerics))(@Raw(methodsArgs))@whereClause
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Interface/IOpenSearchClient.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Interface/IOpenSearchClient.cshtml
index 6b82e4375a..2cef1f859e 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Interface/IOpenSearchClient.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Interface/IOpenSearchClient.cshtml
@@ -3,7 +3,7 @@
@using ApiGenerator.Domain
@using ApiGenerator.Domain.Code
@inherits ApiGenerator.CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
@@ -20,17 +20,16 @@ namespace OpenSearch.Client
///
public partial interface IOpenSearchClient
{
- @foreach(var kv in Model.EndpointsPerNamespaceHighLevel)
+ @foreach(var (ns, endpoints) in Model.EndpointsPerNamespaceHighLevel)
{
- if (kv.Key != CsharpNames.RootNamespace)
+ if (ns != CsharpNames.RootNamespace)
{
- ///@(kv.Key.SplitPascalCase()) APIs
- @CsharpNames.HighLevelClientNamespacePrefix@(kv.Key)@CsharpNames.ClientNamespaceSuffix @kv.Key { get; }
+ ///@ns.SplitPascalCase() APIs
+ @CsharpNames.HighLevelClientNamespacePrefix@(ns)@CsharpNames.ClientNamespaceSuffix @ns { get; }
continue;
}
- var endpoints = kv.Value;
- var models = endpoints.Select(e=>e.HighLevelModel).ToList();
+ var models = endpoints.Select(e=>e.HighLevelModel).ToList();
foreach(var m in models)
{
await IncludeAsync("HighLevel/Client/Interface/MethodInterface.cshtml", m);
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Interface/MethodInterface.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Interface/MethodInterface.cshtml
index e0db8b1671..e9e336e5af 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Interface/MethodInterface.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Interface/MethodInterface.cshtml
@@ -3,27 +3,27 @@
@using HighLevelModel = ApiGenerator.Domain.Code.HighLevel.Methods.HighLevelModel
@inherits CodeTemplatePage
@{
- HighLevelModel model = Model;
- var fluentPath = "HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml";
- var initializerPath = "HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml";
+ const string fluentPath = "HighLevel/Client/FluentSyntax/FluentMethodHeader.cshtml";
+ const string initializerPath = "HighLevel/Client/InitializerSyntax/InitializerMethodHeader.cshtml";
+ const string xmlDocsPath = "HighLevel/Client/MethodXmlDocs.cshtml";
}
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.Fluent); }
-@{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.Fluent, async: false)); };
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.Fluent); }
-@{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.Fluent, async: true)); };
+@{ await IncludeAsync(xmlDocsPath, Model.Fluent); }
+@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: false)); };
+@{ await IncludeAsync(xmlDocsPath, Model.Fluent); }
+@{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.Fluent, async: true)); };
-@if (model.FluentBound != null)
+@if (Model.FluentBound != null)
{
- @{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.FluentBound); }
- @{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.FluentBound, async: false)); };
- @{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.FluentBound); }
- @{ await IncludeAsync(fluentPath, new FluentSyntaxView(model.FluentBound, async: true)); };
+ @{ await IncludeAsync(xmlDocsPath, Model.FluentBound); }
+ @{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: false)); };
+ @{ await IncludeAsync(xmlDocsPath, Model.FluentBound); }
+ @{ await IncludeAsync(fluentPath, new FluentSyntaxView(Model.FluentBound, async: true)); };
}
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.Initializer); }
-@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(model.Initializer, async: false)); };
-@{ await IncludeAsync("HighLevel/Client/MethodXmlDocs.cshtml", model.Initializer); }
-@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(model.Initializer, async: true)); };
+@{ await IncludeAsync(xmlDocsPath, Model.Initializer); }
+@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: false)); };
+@{ await IncludeAsync(xmlDocsPath, Model.Initializer); }
+@{ await IncludeAsync(initializerPath, new InitializerSyntaxView(Model.Initializer, async: true)); };
diff --git a/src/ApiGenerator/Views/HighLevel/Client/MethodXmlDocs.cshtml b/src/ApiGenerator/Views/HighLevel/Client/MethodXmlDocs.cshtml
index e93b97856c..26445d9ea9 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/MethodXmlDocs.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/MethodXmlDocs.cshtml
@@ -1,11 +1,8 @@
@using ApiGenerator
@using ApiGenerator.Domain.Code.HighLevel.Methods;
@inherits CodeTemplatePage
-@{
- var syntax = Model;
-}
///
-/// @Raw(syntax.XmlDocSummary)
+/// @Raw(Model.XmlDocSummary)
/// @Raw("")
-/// @syntax.DocumentationLink
+/// @Model.DocumentationLink
///
diff --git a/src/ApiGenerator/Views/HighLevel/Client/Usings.cshtml b/src/ApiGenerator/Views/HighLevel/Client/Usings.cshtml
index 53dcab591c..807e3e4ed5 100644
--- a/src/ApiGenerator/Views/HighLevel/Client/Usings.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Client/Usings.cshtml
@@ -1,11 +1,11 @@
@using ApiGenerator.Domain
@using ApiGenerator.Domain.Code
@inherits ApiGenerator.CodeTemplatePage
-@foreach(var kv in Model.EndpointsPerNamespaceHighLevel)
+@foreach(var ns in Model.EndpointsPerNamespaceHighLevel.Keys)
{
- if (kv.Key != CsharpNames.RootNamespace)
+ if (ns != CsharpNames.RootNamespace)
{
-using OpenSearch.Client.@(CsharpNames.ApiNamespace).@(kv.Key)@(CsharpNames.ApiNamespaceSuffix);
+using OpenSearch.Client.@(CsharpNames.ApiNamespace).@(ns)@(CsharpNames.ApiNamespaceSuffix);
}
}
diff --git a/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptor.cshtml b/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptor.cshtml
index 49b3fbfdab..6fcd52d0fe 100644
--- a/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptor.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptor.cshtml
@@ -1,33 +1,31 @@
@using System.Linq
@using ApiGenerator
@using ApiGenerator.Domain.Code.HighLevel.Requests
-@using ApiGenerator.Domain.Specification
@using ApiGenerator.Generator
@inherits global::ApiGenerator.CodeTemplatePage
@{
- DescriptorPartialImplementation d = Model;
- var names = d.CsharpNames;
+ var names = Model.CsharpNames;
var type = names.GenericOrNonGenericDescriptorName;
var concreteInterface = names.GenericOrNonGenericInterfaceName;
var baseInterface = names.GenericOrNonGenericInterfacePreference;
- var apiLookup = $"ApiUrlsLookups.{d.CsharpNames.Namespace}{d.CsharpNames.MethodName}";
+ var apiLookup = $"ApiUrlsLookups.{Model.CsharpNames.Namespace}{Model.CsharpNames.MethodName}";
}
- ///Descriptor for @names.MethodName@Raw(d.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + d.OfficialDocumentationLink + "")
+ ///Descriptor for @names.MethodName@(Raw(Model.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + Model.OfficialDocumentationLink + ""))
public partial class @Raw(type) @(Raw(string.Format(" : RequestDescriptorBase<{0},{1}, {2}>, {2}", type,names.ParametersName, concreteInterface)))
{
internal override ApiUrls ApiUrls => @apiLookup;
-@foreach (Constructor c in d.Constructors)
+@foreach (var c in Model.Constructors)
{
@(Raw(CodeGenerator.Constructor(c)))
}
// values part of the url path
-@foreach (UrlPart part in d.Parts)
+@foreach (var part in Model.Parts)
{
@(Raw(part.HighLevelTypeName)) @(Raw(baseInterface)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>",part.HighLevelTypeName)))("@(part.Name)");
}
-@foreach (FluentRouteSetter c in d.GetFluentRouteSetters())
+@foreach (var c in Model.GetFluentRouteSetters())
{
@(Raw(c.XmlDoc))
@@ -35,16 +33,16 @@
}
// Request parameters
-@foreach (var param in d.Params)
+@foreach (var param in Model.Params)
{
var original = param.QueryStringKey;
//skip parameters already part of the path portion of the url
- if (d.Parts.Any(p=>p.Name == original))
+ if (Model.Parts.Any(p=>p.Name == original))
{
continue;
}
//we prefer this parameter to be explictly implemented on the request body
- if (param.RenderPartial && (d.HasBody))
+ if (param.RenderPartial && (Model.HasBody))
{
continue;
}
diff --git a/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptors.cshtml b/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptors.cshtml
index 51ee81f6e7..84f3949367 100644
--- a/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptors.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Descriptors/Descriptors.cshtml
@@ -1,15 +1,13 @@
-@using System.Collections.Generic
@using System.Collections.ObjectModel
@using ApiGenerator
@using ApiGenerator.Domain.Specification
@using ApiGenerator.Domain.Code
@inherits CodeTemplatePage>>
@{
- KeyValuePair> model = Model;
- string ns = model.Key != CsharpNames.RootNamespace ? "."+CsharpNames.ApiNamespace+"." + model.Key + CsharpNames.ApiNamespaceSuffix : null;
- var endpoints = model.Value;
+ var (ns, endpoints) = Model;
+ ns = ns != CsharpNames.RootNamespace ? $".{CsharpNames.ApiNamespace}.{ns}{CsharpNames.ApiNamespaceSuffix}" : null;
}
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
@@ -19,7 +17,7 @@ using System.Linq.Expressions;
using OpenSearch.Net;
using OpenSearch.Net.Utf8Json;
-@if (model.Key != CsharpNames.RootNamespace)
+@if (ns != CsharpNames.RootNamespace)
{
using OpenSearch.Net@(ns);
@@ -35,4 +33,4 @@ namespace OpenSearch.Client
{
await IncludeAsync("HighLevel/Descriptors/Descriptor.cshtml", endpoint.DescriptorPartialImplementation);
}
-}
\ No newline at end of file
+}
diff --git a/src/ApiGenerator/Views/HighLevel/Descriptors/XmlDocs.cshtml b/src/ApiGenerator/Views/HighLevel/Descriptors/XmlDocs.cshtml
index ded98d8e91..5015387ffa 100644
--- a/src/ApiGenerator/Views/HighLevel/Descriptors/XmlDocs.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Descriptors/XmlDocs.cshtml
@@ -1,11 +1,8 @@
-@using System
@using System.Linq
-@using System.Collections.Generic
@inherits ApiGenerator.CodeTemplatePage>
@{
- List summary = Model;
- var description = summary.Count == 1 ? summary.First() : string.Join($"{Environment.NewLine}\t\t", summary.Select(d => "/// " + d));
- if (summary.Count == 1)
+ var description = Model.Count == 1 ? Model.First() : string.Join($"{Environment.NewLine}\t\t", Model.Select(d => "/// " + d));
+ if (Model.Count == 1)
{
///@Raw(description)
}
diff --git a/src/ApiGenerator/Views/HighLevel/Requests/ApiUrlsLookup.cshtml b/src/ApiGenerator/Views/HighLevel/Requests/ApiUrlsLookup.cshtml
index 9f2e38ffc7..92c71f127f 100644
--- a/src/ApiGenerator/Views/HighLevel/Requests/ApiUrlsLookup.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Requests/ApiUrlsLookup.cshtml
@@ -3,15 +3,12 @@
@using ApiGenerator
@using ApiGenerator.Configuration
@inherits CodeTemplatePage
-@{
- RestApiSpec m = Model;
-}
-@{ await IncludeAsync("GeneratorNotice.cshtml", m); }
+@{ await IncludeGeneratorNotice(); }
namespace OpenSearch.Client
{
internal static class ApiUrlsLookups
{
-@foreach (var endpoint in m.Endpoints.Values)
+@foreach (var endpoint in Model.Endpoints.Values)
{
if (CodeConfiguration.IgnoreHighLevelApi(endpoint.Name))
{
@@ -24,4 +21,4 @@ namespace OpenSearch.Client
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ApiGenerator/Views/HighLevel/Requests/PlainRequestBase.cshtml b/src/ApiGenerator/Views/HighLevel/Requests/PlainRequestBase.cshtml
index 2a0780adb1..b042d9c1e5 100644
--- a/src/ApiGenerator/Views/HighLevel/Requests/PlainRequestBase.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Requests/PlainRequestBase.cshtml
@@ -1,7 +1,6 @@
-@using System.Linq
@using ApiGenerator.Domain
@inherits ApiGenerator.CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
diff --git a/src/ApiGenerator/Views/HighLevel/Requests/RequestImplementations.cshtml b/src/ApiGenerator/Views/HighLevel/Requests/RequestImplementations.cshtml
index a1bdfb1963..af7b516e5a 100644
--- a/src/ApiGenerator/Views/HighLevel/Requests/RequestImplementations.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Requests/RequestImplementations.cshtml
@@ -1,20 +1,17 @@
@using System.Linq
@using ApiGenerator
-@using ApiGenerator.Domain.Code
@using ApiGenerator.Domain.Code.HighLevel.Requests
@using ApiGenerator.Domain.Specification
@using ApiGenerator.Generator
@inherits global::ApiGenerator.CodeTemplatePage
@{
- RequestPartialImplementation r = Model;
- CsharpNames names = r.CsharpNames;
- var apiLookup = $"ApiUrlsLookups.{r.CsharpNames.Namespace}{r.CsharpNames.MethodName}";
+ var apiLookup = $"ApiUrlsLookups.{Model.CsharpNames.Namespace}{Model.CsharpNames.MethodName}";
}
-///Request for @names.MethodName@Raw(r.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + r.OfficialDocumentationLink + "")
-@if (r.Stability != Stability.Stable)
+///Request for @Model.CsharpNames.MethodName@(Raw(Model.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + Model.OfficialDocumentationLink + ""))
+@if (Model.Stability != Stability.Stable)
{
string warningMessage = "";
- switch (r.Stability)
+ switch (Model.Stability)
{
case Stability.Experimental:
warningMessage = "this functionality is experimental and may be changed or removed completely in a future release. OpenSearch will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.";
@@ -24,59 +21,58 @@
break;
}
-///@Raw("Note: " + r.Stability + " within the OpenSearch server, " + warningMessage + "")
-
-}
- public partial class @Raw(r.Name) @Raw(string.Format(": PlainRequestBase<{0}>, {1}", names.ParametersName, r.InterfaceName))
- {
- protected @(Raw(r.InterfaceName)) Self => this;
+///@Raw("Note: " + Model.Stability + " within the OpenSearch server, " + warningMessage + "")
+
+}
+ public partial class @Raw(Model.Name) @Raw(string.Format(": PlainRequestBase<{0}>, {1}", Model.CsharpNames.ParametersName, Model.InterfaceName))
+{
+ protected @Raw(Model.InterfaceName) Self => this;
internal override ApiUrls ApiUrls => @apiLookup;
-@foreach (Constructor c in r.Constructors)
+@foreach (var c in Model.Constructors)
{
@(Raw(CodeGenerator.Constructor(c)))
}
// values part of the url path
-@foreach (var part in r.Parts)
+@foreach (var part in Model.Parts)
{
[IgnoreDataMember]
- @(Raw(part.HighLevelTypeName)) @(Raw(r.InterfaceName)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>", part.HighLevelTypeName)))("@(part.Name)");
+ @(Raw(part.HighLevelTypeName)) @(Raw(Model.InterfaceName)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>", part.HighLevelTypeName)))("@(part.Name)");
}
// Request parameters
-@foreach (var param in r.Params)
+@foreach (var param in Model.Params)
{
var original = param.QueryStringKey;
//skip parameters already part of the path portion of the url
- if (r.Parts.Any(p=>p.Name == original))
+ if (Model.Parts.Any(p=>p.Name == original))
{
continue;
}
// We prefer to map these explicitly in our own hand written classes.
// The interface generation will generate properties for these so code won't compile until we do
- if (param.RenderPartial && (r.HasBody))
+ if (param.RenderPartial && (Model.HasBody))
{
continue;
}
var doc = param.DescriptionHighLevel.ToArray();
- @Raw(param.InitializerGenerator(r.CsharpNames.Namespace, param.TypeHighLevel, param.ClsName, original, param.SetterHighLevel, doc))
-
+ @Raw(param.InitializerGenerator(Model.CsharpNames.Namespace, param.TypeHighLevel, param.ClsName, original, param.SetterHighLevel, doc))
}
-@if (names.DescriptorNotFoundInCodebase)
+@if (Model.CsharpNames.DescriptorNotFoundInCodebase)
{
- [Obsolete("Unmapped, blacklist this API in CodeConfiguration.cs or implement @names.DescriptorName and @names.RequestName in a file called @(names.RequestName).cs in OSC's codebase", true)]
+ [Obsolete("Unmapped, blacklist this API in CodeConfiguration.cs or implement @Model.CsharpNames.DescriptorName and @Model.CsharpNames.RequestName in a file called @(Model.CsharpNames.RequestName).cs in OSC's codebase", true)]
public bool IsUnmapped => true;
public bool UseIsUnmapped => IsUnmapped;
}
}
-@if (r.NeedsGenericImplementation)
+@if (Model.NeedsGenericImplementation)
{
- public partial class @Raw(names.GenericRequestName) @Raw(string.Format(": {0}, {1}", names.RequestName, names.GenericInterfaceName))
+ public partial class @Raw(Model.CsharpNames.GenericRequestName) @Raw(string.Format(": {0}, {1}", Model.CsharpNames.RequestName, Model.CsharpNames.GenericInterfaceName))
{
- protected @(Raw(names.GenericInterfaceName)) TypedSelf => this;
-@foreach (Constructor c in r.GenericConstructors)
+ protected @Raw(Model.CsharpNames.GenericInterfaceName) TypedSelf => this;
+@foreach (Constructor c in Model.GenericConstructors)
{
@(Raw(CodeGenerator.Constructor(c)))
diff --git a/src/ApiGenerator/Views/HighLevel/Requests/RequestInterface.cshtml b/src/ApiGenerator/Views/HighLevel/Requests/RequestInterface.cshtml
index ad5642216b..efe0da4f29 100644
--- a/src/ApiGenerator/Views/HighLevel/Requests/RequestInterface.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Requests/RequestInterface.cshtml
@@ -1,27 +1,25 @@
@using ApiGenerator.Domain.Code.HighLevel.Requests
-@using ApiGenerator.Domain.Specification
@inherits ApiGenerator.CodeTemplatePage
@{
- RequestInterface i = Model;
- string name = i.CsharpNames.RequestInterfaceName;
+ var name = Model.CsharpNames.RequestInterfaceName;
}
[InterfaceDataContract]
- public partial interface @(Raw(i.Name)) : IRequest@(Raw(string.Format("<{0}>", i.CsharpNames.ParametersName)))
- {
-@foreach (UrlPart part in i.UrlParts)
+ public partial interface @Raw(Model.Name) : IRequest@(Raw(string.Format("<{0}>", Model.CsharpNames.ParametersName)))
+{
+@foreach (var part in Model.UrlParts)
{
[IgnoreDataMember]
@(Raw(part.HighLevelTypeName)) @(part.InterfaceName) { get; }
}
-@foreach (var partialParam in i.PartialParameters)
+@foreach (var partialParam in Model.PartialParameters)
{
[DataMember(Name = "@(partialParam.QueryStringKey)")] @(Raw(partialParam.TypeHighLevel)) @(partialParam.ClsName) { get; set; }
}
}
-@if (i.NeedsGenericInterface)
+@if (Model.NeedsGenericInterface)
{
- public partial interface @(name)@(Raw(i.CsharpNames.GenericsDeclaredOnRequest)) : @(Raw(name)) { }
+ public partial interface @(name)@Raw(Model.CsharpNames.GenericsDeclaredOnRequest) : @(Raw(name)) { }
}
diff --git a/src/ApiGenerator/Views/HighLevel/Requests/Requests.cshtml b/src/ApiGenerator/Views/HighLevel/Requests/Requests.cshtml
index e55ea5a1ee..3263b77c3f 100644
--- a/src/ApiGenerator/Views/HighLevel/Requests/Requests.cshtml
+++ b/src/ApiGenerator/Views/HighLevel/Requests/Requests.cshtml
@@ -1,15 +1,13 @@
-@using System.Collections.Generic
@using System.Collections.ObjectModel
@using ApiGenerator
@using ApiGenerator.Domain.Specification
@using ApiGenerator.Domain.Code
@inherits CodeTemplatePage>>
@{
- KeyValuePair> model = Model;
- string ns = model.Key != CsharpNames.RootNamespace ? "."+CsharpNames.ApiNamespace+"." + model.Key + CsharpNames.ApiNamespaceSuffix : null;
- var endpoints = model.Value;
+ var (ns, endpoints) = Model;
+ ns = ns != CsharpNames.RootNamespace ? $".{CsharpNames.ApiNamespace}.{ns}{CsharpNames.ApiNamespaceSuffix}" : null;
}
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
@@ -19,7 +17,7 @@ using System.Linq.Expressions;
using System.Runtime.Serialization;
using OpenSearch.Net;
using OpenSearch.Net.Utf8Json;
-@if (model.Key != CsharpNames.RootNamespace)
+@if (ns != CsharpNames.RootNamespace)
{
using OpenSearch.Net@(ns);
@@ -36,4 +34,4 @@ namespace OpenSearch.Client
await IncludeAsync("HighLevel/Requests/RequestInterface.cshtml", endpoint.RequestInterface);
await IncludeAsync("HighLevel/Requests/RequestImplementations.cshtml", endpoint.RequestPartialImplementation);
}
-}
\ No newline at end of file
+}
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.Namespace.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.Namespace.cshtml
index 9ec2f9c3a1..87a06d99a4 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.Namespace.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.Namespace.cshtml
@@ -1,15 +1,12 @@
-@using System.Collections.Generic
@using System.Collections.ObjectModel
@using System.Linq
@using ApiGenerator
@using ApiGenerator.Domain.Code
@using ApiGenerator.Domain.Specification
@inherits CodeTemplatePage>>
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
@{
- KeyValuePair> model = Model;
- string ns = model.Key;
- var endpoints = model.Value;
+ var (ns, endpoints) = Model;
}
// ReSharper disable RedundantUsingDirective
using System;
@@ -26,17 +23,17 @@ using static OpenSearch.Net.HttpMethod;
// ReSharper disable once CheckNamespace
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
// ReSharper disable RedundantExtendsListEntry
-namespace OpenSearch.Net.@(CsharpNames.ApiNamespace).@(ns)@(CsharpNames.ApiNamespaceSuffix)
+namespace OpenSearch.Net.@(CsharpNames.ApiNamespace).@ns@(CsharpNames.ApiNamespaceSuffix)
{
///
- /// @(ns.SplitPascalCase()) APIs.
+ /// @ns.SplitPascalCase() APIs.
/// Not intended to be instantiated directly. Use the property
/// on .
///
///
- public partial class @(CsharpNames.LowLevelClientNamespacePrefix)@(model.Key)@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
+ public partial class @(CsharpNames.LowLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix) : NamespacedClientProxy
{
- internal @(CsharpNames.LowLevelClientNamespacePrefix)@(model.Key)@(CsharpNames.ClientNamespaceSuffix)(OpenSearchLowLevelClient client) : base(client) {}
+ internal @(CsharpNames.LowLevelClientNamespacePrefix)@ns@(CsharpNames.ClientNamespaceSuffix)(OpenSearchLowLevelClient client) : base(client) {}
@if (ns == "Cat")
{
protected override string ContentType { get; } = "text/plain";
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.cshtml
index a4ce6b2159..84722f9763 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Implementation/OpenSearchLowLevelClient.cshtml
@@ -3,7 +3,7 @@
@using ApiGenerator
@using ApiGenerator.Domain.Code
@inherits CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
@@ -17,8 +17,7 @@ using OpenSearch.Net;
using static OpenSearch.Net.HttpMethod;
@{
- RestApiSpec model = Model;
- var namespaces = model.EndpointsPerNamespaceLowLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
+ var namespaces = Model.EndpointsPerNamespaceLowLevel.Keys.Where(k => k != CsharpNames.RootNamespace).ToList();
// ReSharper disable InterpolatedStringExpressionIsNotIFormattable
// ReSharper disable RedundantExtendsListEntry
@@ -49,14 +48,13 @@ namespace OpenSearch.Net
- foreach (var kv in model.EndpointsPerNamespaceLowLevel)
+ foreach (var (ns, endpoints) in Model.EndpointsPerNamespaceLowLevel)
{
- if (kv.Key != CsharpNames.RootNamespace)
+ if (ns != CsharpNames.RootNamespace)
{
continue;
}
- var endpoints = kv.Value;
- var methods = endpoints.SelectMany(e=>e.LowLevelClientMethods).ToList();
+ var methods = endpoints.SelectMany(e=>e.LowLevelClientMethods).ToList();
foreach (var method in methods)
{
await IncludeAsync("LowLevel/Client/Methods/MethodImplementation.cshtml", method);
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Interface/IOpenSearchLowLevelClient.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Interface/IOpenSearchLowLevelClient.cshtml
index beadac4ff0..c18cf883b8 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Interface/IOpenSearchLowLevelClient.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Interface/IOpenSearchLowLevelClient.cshtml
@@ -3,7 +3,7 @@
@using ApiGenerator.Domain
@using ApiGenerator.Domain.Code
@inherits ApiGenerator.CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
@@ -22,18 +22,17 @@ namespace OpenSearch.Net
///
public partial interface IOpenSearchLowLevelClient
{
- @foreach(var kv in Model.EndpointsPerNamespaceLowLevel)
+ @foreach(var (ns, endpoints) in Model.EndpointsPerNamespaceLowLevel)
{
- if (kv.Key != CsharpNames.RootNamespace)
+ if (ns != CsharpNames.RootNamespace)
{
- ///@(kv.Key.SplitPascalCase()) APIs
- @CsharpNames.LowLevelClientNamespacePrefix@(kv.Key)@CsharpNames.ClientNamespaceSuffix @kv.Key { get; }
+ ///@ns.SplitPascalCase() APIs
+ @CsharpNames.LowLevelClientNamespacePrefix@(ns)@CsharpNames.ClientNamespaceSuffix @ns { get; }
continue;
}
- var endpoints = kv.Value;
- var methods = endpoints.SelectMany(e=>e.LowLevelClientMethods).ToList();
+ var methods = endpoints.SelectMany(e=>e.LowLevelClientMethods).ToList();
foreach(var method in methods)
{
await IncludeAsync("LowLevel/Client/Methods/MethodInterface.cshtml", method);
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodDocs.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodDocs.cshtml
index d4948097ab..46423d412d 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodDocs.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodDocs.cshtml
@@ -2,20 +2,17 @@
@using ApiGenerator.Domain.Code.LowLevel
@using ApiGenerator.Domain.Specification
@inherits ApiGenerator.CodeTemplatePage
-@{
- LowLevelClientMethod method = Model;
-}
- ///@method.HttpMethod on @method.Path@Raw(method.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + method.OfficialDocumentationLink + "")
-@foreach (var part in method.Parts)
+///@Model.HttpMethod on @Model.Path@(Raw(Model.OfficialDocumentationLink.IsNullOrEmpty() ? "" : " " + Model.OfficialDocumentationLink + ""))
+@foreach (var part in Model.Parts)
{
///@Raw("")@part.Description@Raw("")
}
///@Raw(@"Request specific configuration such as querystring parameters & request specific connection settings.")
- @if (method.Stability != Stability.Stable)
+ @if (Model.Stability != Stability.Stable)
{
string warningMessage = "";
- switch (method.Stability)
+ switch (Model.Stability)
{
case Stability.Experimental:
warningMessage = "this functionality is Experimental and may be changed or removed completely in a future release. OpenSearch will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.";
@@ -27,10 +24,10 @@
warningMessage += " This functionality is subject to potential breaking changes within a minor version, meaning that your referencing code may break when this library is upgraded.";
- ///@Raw("Note: " + method.Stability + " within the OpenSearch server, " + warningMessage + "")
-
- }
- @if (method.DeprecatedPath != null)
+ ///@Raw("Note: " + Model.Stability + " within the OpenSearch server, " + warningMessage + "")
+
+}
+ @if (Model.DeprecatedPath != null)
{
- [Obsolete("Deprecated in version @(method.DeprecatedPath.Version): @Raw(method.DeprecatedPath.Description)")]
+ [Obsolete("Deprecated in version @Model.DeprecatedPath.Version: @Raw(Model.DeprecatedPath.Description)")]
}
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodImplementation.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodImplementation.cshtml
index 211a1f5dc8..d0ececa4ef 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodImplementation.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodImplementation.cshtml
@@ -1,14 +1,13 @@
@using ApiGenerator.Domain.Code.LowLevel
@inherits ApiGenerator.CodeTemplatePage
@{
- LowLevelClientMethod method = Model;
- var contentType = method.CsharpNames.RestSpecName.Contains(".cat_") ? ", contentType: \"text/plain\"" : string.Empty;
+ var contentType = Model.CsharpNames.RestSpecName.Contains(".cat_") ? ", contentType: \"text/plain\"" : string.Empty;
}
-@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", method); }
- public TResponse @(method.PerPathMethodName)@(Raw(""))(@Raw(method.Arguments))
- where TResponse : class, IOpenSearchResponse, new() => DoRequest@(Raw(""))(@method.HttpMethod, @Raw(method.UrlInCode), @(method.HasBody ? "body" : "null"), RequestParams(requestParameters@(Raw(contentType))));
+@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", Model); }
+ public TResponse @Model.PerPathMethodName@(Raw(""))(@Raw(Model.Arguments))
+ where TResponse : class, IOpenSearchResponse, new() => DoRequest@(Raw(""))(@Model.HttpMethod, @Raw(Model.UrlInCode), @(Model.HasBody ? "body" : "null"), RequestParams(requestParameters@(Raw(contentType))));
-@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", method); }
- [MapsApi("@(method.CsharpNames.RestSpecName)", "@(method.MapsApiArguments)")]
- public Task@(Raw("")) @(method.PerPathMethodName)Async@(Raw(""))(@Raw(method.Arguments), CancellationToken ctx = default)
- where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync@(Raw(""))(@method.HttpMethod, @Raw(method.UrlInCode), ctx, @(method.HasBody ? "body" : "null"), RequestParams(requestParameters@(Raw(contentType))));
+@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", Model); }
+ [MapsApi("@Model.CsharpNames.RestSpecName", "@Model.MapsApiArguments")]
+ public Task@(Raw("")) @(Model.PerPathMethodName)Async@(Raw(""))(@Raw(Model.Arguments), CancellationToken ctx = default)
+ where TResponse : class, IOpenSearchResponse, new() => DoRequestAsync@(Raw(""))(@Model.HttpMethod, @Raw(Model.UrlInCode), ctx, @(Model.HasBody ? "body" : "null"), RequestParams(requestParameters@(Raw(contentType))));
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodInterface.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodInterface.cshtml
index be8bef61ae..26af0feff8 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodInterface.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Methods/MethodInterface.cshtml
@@ -1,10 +1,7 @@
@using ApiGenerator.Domain.Code.LowLevel
@inherits ApiGenerator.CodeTemplatePage
-@{
- LowLevelClientMethod method = Model;
-}
-@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", method); }
- TResponse @(method.PerPathMethodName)@(Raw(""))(@Raw(method.Arguments)) where TResponse : class, IOpenSearchResponse, new();
+@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", Model); }
+ TResponse @Model.PerPathMethodName@(Raw(""))(@Raw(Model.Arguments)) where TResponse : class, IOpenSearchResponse, new();
-@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", method); }
- Task@(Raw("")) @(method.PerPathMethodName)Async@(Raw(""))(@Raw(method.Arguments), CancellationToken ctx = default) where TResponse : class, IOpenSearchResponse, new();
+@{await IncludeAsync("LowLevel/Client/Methods/MethodDocs.cshtml", Model); }
+ Task@(Raw("")) @(Model.PerPathMethodName)Async@(Raw(""))(@Raw(Model.Arguments), CancellationToken ctx = default) where TResponse : class, IOpenSearchResponse, new();
diff --git a/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml b/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml
index 3222da33a8..7dcc951284 100644
--- a/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Client/Usings.cshtml
@@ -1,11 +1,11 @@
@using ApiGenerator.Domain
@using ApiGenerator.Domain.Code
@inherits ApiGenerator.CodeTemplatePage
-@foreach(var kv in Model.EndpointsPerNamespaceLowLevel)
+@foreach(var ns in Model.EndpointsPerNamespaceLowLevel.Keys)
{
- if (kv.Key != CsharpNames.RootNamespace)
+ if (ns != CsharpNames.RootNamespace)
{
-using OpenSearch.Net.@(CsharpNames.ApiNamespace).@(kv.Key)@(CsharpNames.ApiNamespaceSuffix);
+using OpenSearch.Net.@(CsharpNames.ApiNamespace).@(ns)@(CsharpNames.ApiNamespaceSuffix);
}
}
diff --git a/src/ApiGenerator/Views/LowLevel/Enums.Generated.cshtml b/src/ApiGenerator/Views/LowLevel/Enums.Generated.cshtml
index d669011d30..3d4cb84b83 100644
--- a/src/ApiGenerator/Views/LowLevel/Enums.Generated.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/Enums.Generated.cshtml
@@ -1,11 +1,10 @@
-@using System
@using System.Linq
@using System.Text
@using ApiGenerator.Domain
@using ApiGenerator
@using ApiGenerator.Configuration.Overrides
@inherits CodeTemplatePage
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
@functions {
private const string RawSize = "Raw";
private const string SizeEnum = "Size";
@@ -54,7 +53,7 @@ using System.Runtime.Serialization;
namespace OpenSearch.Net
{
-@foreach (EnumDescription e in Model.EnumsInTheSpec)
+@foreach (var e in Model.EnumsInTheSpec)
{
var isFlag = IsFlag(e.Name);
@@ -70,7 +69,7 @@ namespace OpenSearch.Net
static KnownEnums()
{
- @foreach (EnumDescription e in Model.EnumsInTheSpec)
+ @foreach (var e in Model.EnumsInTheSpec)
{
EnumStringResolvers.TryAdd(typeof(@(e.Name)), (e) => GetStringValue((@(e.Name))e));
@@ -83,7 +82,7 @@ namespace OpenSearch.Net
public @(Raw("Func")) Resolver { get; set; }
}
- @foreach (EnumDescription e in Model.EnumsInTheSpec)
+ @foreach (var e in Model.EnumsInTheSpec)
{
var isFlag = IsFlag(e.Name);
@@ -170,4 +169,4 @@ namespace OpenSearch.Net
};
}
}
-}
\ No newline at end of file
+}
diff --git a/src/ApiGenerator/Views/LowLevel/RequestParameters/RequestParameters.cshtml b/src/ApiGenerator/Views/LowLevel/RequestParameters/RequestParameters.cshtml
index 79ec395893..78c4862f41 100644
--- a/src/ApiGenerator/Views/LowLevel/RequestParameters/RequestParameters.cshtml
+++ b/src/ApiGenerator/Views/LowLevel/RequestParameters/RequestParameters.cshtml
@@ -1,14 +1,12 @@
-@using System.Collections.Generic
@using System.Collections.ObjectModel
@using ApiGenerator
@using ApiGenerator.Domain.Code
@using ApiGenerator.Domain.Specification
@inherits CodeTemplatePage>>
-@{ await IncludeAsync("GeneratorNotice.cshtml", Model); }
+@{ await IncludeGeneratorNotice(); }
@{
- KeyValuePair> model = Model;
- string ns = model.Key != CsharpNames.RootNamespace ? "."+CsharpNames.ApiNamespace+"." + model.Key + CsharpNames.ApiNamespaceSuffix : null;
- var endpoints = model.Value;
+ var (ns, endpoints) = Model;
+ ns = ns != CsharpNames.RootNamespace ? $".{CsharpNames.ApiNamespace}.{ns}{CsharpNames.ApiNamespaceSuffix}" : null;
}
// ReSharper disable RedundantUsingDirective
diff --git a/src/ApiGenerator/packages.lock.json b/src/ApiGenerator/packages.lock.json
index 5fd411a17e..38fa2a08a1 100644
--- a/src/ApiGenerator/packages.lock.json
+++ b/src/ApiGenerator/packages.lock.json
@@ -39,9 +39,9 @@
},
"RazorLight": {
"type": "Direct",
- "requested": "[2.1.0, )",
- "resolved": "2.1.0",
- "contentHash": "WUJUsOJXUXrRpMrlWunn2QsOigF07S+lP2QxuOEBlfswDtuO4SAGaL97tOn0Hq24lMNqR4SWepOMj4Rlx+OfsQ==",
+ "requested": "[2.3.1, )",
+ "resolved": "2.3.1",
+ "contentHash": "Eegx5xEQ2AvydJB5lHTZgIQQyCZJ6NLJb1ePinAGmv5S42rvj8o/FRZFxrB0jQhXmA4uu93x+J/ZVE1qBv4dLw==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Razor.Extensions": "6.0.0",
"Microsoft.CodeAnalysis.Razor": "6.0.0",