Refactor LibKubernetesGenerator code structure (#1546)
* Refactor LibKubernetesGenerator code structure * clean up comment out code * No more locks * clean up dep * Update dependency paths in LibKubernetesGenerator.target
This commit is contained in:
@@ -8,6 +8,13 @@ namespace LibKubernetesGenerator
|
|||||||
{
|
{
|
||||||
internal class ApiGenerator
|
internal class ApiGenerator
|
||||||
{
|
{
|
||||||
|
private readonly ScriptObjectFactory scriptObjectFactory;
|
||||||
|
|
||||||
|
public ApiGenerator(ScriptObjectFactory scriptObjectFactory)
|
||||||
|
{
|
||||||
|
this.scriptObjectFactory = scriptObjectFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||||
{
|
{
|
||||||
var data = swagger.Operations
|
var data = swagger.Operations
|
||||||
@@ -42,6 +49,8 @@ namespace LibKubernetesGenerator
|
|||||||
})
|
})
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
|
var sc = scriptObjectFactory.CreateScriptObject();
|
||||||
|
|
||||||
var groups = new List<string>();
|
var groups = new List<string>();
|
||||||
|
|
||||||
foreach (var grouped in data.GroupBy(d => d.Operation.Tags.First()))
|
foreach (var grouped in data.GroupBy(d => d.Operation.Tags.First()))
|
||||||
@@ -50,14 +59,20 @@ namespace LibKubernetesGenerator
|
|||||||
groups.Add(name);
|
groups.Add(name);
|
||||||
|
|
||||||
var apis = grouped.ToArray();
|
var apis = grouped.ToArray();
|
||||||
var gctx = new { name, apis };
|
|
||||||
context.RenderToContext($"IOperations.cs.template", gctx, $"I{name}Operations.g.cs");
|
sc.SetValue("name", name, true);
|
||||||
context.RenderToContext("Operations.cs.template", gctx, $"{name}Operations.g.cs");
|
sc.SetValue("apis", apis, true);
|
||||||
context.RenderToContext("OperationsExtensions.cs.template", gctx, $"{name}OperationsExtensions.g.cs");
|
|
||||||
|
context.RenderToContext($"IOperations.cs.template", sc, $"I{name}Operations.g.cs");
|
||||||
|
context.RenderToContext("Operations.cs.template", sc, $"{name}Operations.g.cs");
|
||||||
|
context.RenderToContext("OperationsExtensions.cs.template", sc, $"{name}OperationsExtensions.g.cs");
|
||||||
}
|
}
|
||||||
|
|
||||||
context.RenderToContext($"IBasicKubernetes.cs.template", groups, $"IBasicKubernetes.g.cs");
|
sc = scriptObjectFactory.CreateScriptObject();
|
||||||
context.RenderToContext($"AbstractKubernetes.cs.template", groups, $"AbstractKubernetes.g.cs");
|
sc.SetValue("groups", groups, true);
|
||||||
|
|
||||||
|
context.RenderToContext($"IBasicKubernetes.cs.template", sc, $"IBasicKubernetes.g.cs");
|
||||||
|
context.RenderToContext($"AbstractKubernetes.cs.template", sc, $"AbstractKubernetes.g.cs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
using CaseExtensions;
|
using CaseExtensions;
|
||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class ClassNameHelper : INustacheHelper
|
internal class ClassNameHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, string> classNameMap;
|
private readonly Dictionary<string, string> classNameMap;
|
||||||
private readonly Dictionary<JsonSchema, string> schemaToNameMapCooked;
|
private readonly Dictionary<JsonSchema, string> schemaToNameMapCooked;
|
||||||
@@ -18,9 +19,10 @@ namespace LibKubernetesGenerator
|
|||||||
schemaToNameMapCooked = GenerateSchemaToNameMapCooked(swagger);
|
schemaToNameMapCooked = GenerateSchemaToNameMapCooked(swagger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
|
||||||
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(GetClassName), GetClassName);
|
scriptObject.Import(nameof(GetClassName), new Func<JsonSchema, string>(GetClassNameForSchemaDefinition));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<JsonSchema, string> GenerateSchemaToNameMapCooked(OpenApiDocument swagger)
|
private static Dictionary<JsonSchema, string> GenerateSchemaToNameMapCooked(OpenApiDocument swagger)
|
||||||
@@ -50,27 +52,7 @@ namespace LibKubernetesGenerator
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetClassName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
private string GetClassName(Dictionary<string, object> groupVersionKind)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiOperation)
|
|
||||||
{
|
|
||||||
context.Write(GetClassName(arguments[0] as OpenApiOperation));
|
|
||||||
}
|
|
||||||
else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
context.Write(GetClassNameForSchemaDefinition(arguments[0] as JsonSchema));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetClassName(OpenApiOperation operation)
|
|
||||||
{
|
|
||||||
var groupVersionKind =
|
|
||||||
(Dictionary<string, object>)operation.ExtensionData["x-kubernetes-group-version-kind"];
|
|
||||||
return GetClassName(groupVersionKind);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetClassName(Dictionary<string, object> groupVersionKind)
|
|
||||||
{
|
{
|
||||||
var group = (string)groupVersionKind["group"];
|
var group = (string)groupVersionKind["group"];
|
||||||
var kind = (string)groupVersionKind["kind"];
|
var kind = (string)groupVersionKind["kind"];
|
||||||
@@ -98,10 +80,5 @@ namespace LibKubernetesGenerator
|
|||||||
|
|
||||||
return schemaToNameMapCooked[definition];
|
return schemaToNameMapCooked[definition];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<JsonSchema, string> InitSchemaToNameCooked(OpenApiDocument swagger)
|
|
||||||
{
|
|
||||||
return swagger.Definitions.ToDictionary(x => x.Value, x => x.Key.Replace(".", "").ToPascalCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using CaseExtensions;
|
using CaseExtensions;
|
||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class GeneralNameHelper : INustacheHelper
|
internal class GeneralNameHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly ClassNameHelper classNameHelper;
|
private readonly ClassNameHelper classNameHelper;
|
||||||
|
|
||||||
@@ -17,20 +18,12 @@ namespace LibKubernetesGenerator
|
|||||||
this.classNameHelper = classNameHelper;
|
this.classNameHelper = classNameHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(GetInterfaceName), GetInterfaceName);
|
scriptObject.Import(nameof(GetInterfaceName), new Func<JsonSchema, string>(GetInterfaceName));
|
||||||
Helpers.Register(nameof(GetMethodName), GetMethodName);
|
scriptObject.Import(nameof(GetMethodName), new Func<OpenApiOperation, string, string>(GetMethodName));
|
||||||
Helpers.Register(nameof(GetDotNetName), GetDotNetName);
|
scriptObject.Import(nameof(GetDotNetName), new Func<string, string, string>(GetDotNetName));
|
||||||
}
|
scriptObject.Import(nameof(GetDotNetNameOpenApiParameter), new Func<OpenApiParameter, string, string>(GetDotNetNameOpenApiParameter));
|
||||||
|
|
||||||
public void GetInterfaceName(RenderContext context, IList<object> arguments,
|
|
||||||
IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
context.Write(GetInterfaceName(arguments[0] as JsonSchema));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetInterfaceName(JsonSchema definition)
|
private string GetInterfaceName(JsonSchema definition)
|
||||||
@@ -68,44 +61,16 @@ namespace LibKubernetesGenerator
|
|||||||
return string.Join(", ", interfaces);
|
return string.Join(", ", interfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetMethodName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
public string GetDotNetNameOpenApiParameter(OpenApiParameter parameter, string init)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiOperation)
|
var name = GetDotNetName(parameter.Name);
|
||||||
|
|
||||||
|
if (init == "true" && !parameter.IsRequired)
|
||||||
{
|
{
|
||||||
string suffix = null;
|
name += " = null";
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
suffix = arguments[1] as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Write(GetMethodName(arguments[0] as OpenApiOperation, suffix));
|
return name;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetDotNetName(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiParameter)
|
|
||||||
{
|
|
||||||
var parameter = arguments[0] as OpenApiParameter;
|
|
||||||
context.Write(GetDotNetName(parameter.Name));
|
|
||||||
|
|
||||||
if (arguments.Count > 1 && (arguments[1] as string) == "true" && !parameter.IsRequired)
|
|
||||||
{
|
|
||||||
context.Write(" = null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is string)
|
|
||||||
{
|
|
||||||
var style = "parameter";
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
style = arguments[1] as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Write(GetDotNetName((string)arguments[0], style));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDotNetName(string jsonName, string style = "parameter")
|
public string GetDotNetName(string jsonName, string style = "parameter")
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using Nustache.Core;
|
using Scriban;
|
||||||
|
using Scriban.Runtime;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal static class GeneratorExecutionContextExt
|
internal static class GeneratorExecutionContextExt
|
||||||
{
|
{
|
||||||
public static void RenderToContext(this IncrementalGeneratorPostInitializationContext context, string templatefile, object data, string generatedfile)
|
public static void RenderToContext(this IncrementalGeneratorPostInitializationContext context, string templatefile, ScriptObject sc, string generatedfile)
|
||||||
{
|
{
|
||||||
var template = EmbedResource.GetResource(templatefile);
|
var tc = new TemplateContext();
|
||||||
var generated = Render.StringToString(template, data);
|
tc.PushGlobal(sc);
|
||||||
|
context.RenderToContext(templatefile, tc, generatedfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RenderToContext(this IncrementalGeneratorPostInitializationContext context, string templatefile, TemplateContext tc, string generatedfile)
|
||||||
|
{
|
||||||
|
var template = Template.Parse(EmbedResource.GetResource(templatefile));
|
||||||
|
var generated = template.Render(tc);
|
||||||
context.AddSource(generatedfile, SourceText.From(generated, Encoding.UTF8));
|
context.AddSource(generatedfile, SourceText.From(generated, Encoding.UTF8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace LibKubernetesGenerator
|
|
||||||
{
|
|
||||||
public interface INustacheHelper
|
|
||||||
{
|
|
||||||
void RegisterHelper();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
src/LibKubernetesGenerator/IScriptObjectHelper.cs
Normal file
8
src/LibKubernetesGenerator/IScriptObjectHelper.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Scriban.Runtime;
|
||||||
|
|
||||||
|
namespace LibKubernetesGenerator;
|
||||||
|
|
||||||
|
internal interface IScriptObjectHelper
|
||||||
|
{
|
||||||
|
void RegisterHelper(ScriptObject scriptObject);
|
||||||
|
}
|
||||||
@@ -1,38 +1,22 @@
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
|
||||||
#if GENERATE_AUTOMAPPER
|
#if GENERATE_AUTOMAPPER
|
||||||
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#endif
|
#endif
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
[Generator]
|
[Generator]
|
||||||
public class KubernetesClientSourceGenerator : IIncrementalGenerator
|
public class KubernetesClientSourceGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
private static readonly object Execlock = new object();
|
|
||||||
|
|
||||||
private static (OpenApiDocument, IContainer) BuildContainer()
|
private static (OpenApiDocument, IContainer) BuildContainer()
|
||||||
{
|
{
|
||||||
var swagger = OpenApiDocument.FromJsonAsync(EmbedResource.GetResource("swagger.json")).GetAwaiter().GetResult();
|
var swagger = OpenApiDocument.FromJsonAsync(EmbedResource.GetResource("swagger.json")).GetAwaiter().GetResult();
|
||||||
var container = BuildContainer(swagger);
|
var container = BuildContainer(swagger);
|
||||||
// TODO move to Handlebars.Net
|
|
||||||
// here is to clean up the custom helpers in static Nustache.Core.Helpers
|
|
||||||
{
|
|
||||||
var ch = typeof(Helpers).GetField("CustomHelpers", BindingFlags.Static | BindingFlags.NonPublic);
|
|
||||||
((Dictionary<string, Helper>)ch.GetValue(null)).Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var helper in container.Resolve<IEnumerable<INustacheHelper>>())
|
|
||||||
{
|
|
||||||
helper.RegisterHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (swagger, container);
|
return (swagger, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +61,9 @@ namespace LibKubernetesGenerator
|
|||||||
.AsImplementedInterfaces()
|
.AsImplementedInterfaces()
|
||||||
;
|
;
|
||||||
|
|
||||||
|
builder.RegisterType<ScriptObjectFactory>()
|
||||||
|
;
|
||||||
|
|
||||||
builder.RegisterType<ModelExtGenerator>();
|
builder.RegisterType<ModelExtGenerator>();
|
||||||
builder.RegisterType<ModelGenerator>();
|
builder.RegisterType<ModelGenerator>();
|
||||||
builder.RegisterType<ApiGenerator>();
|
builder.RegisterType<ApiGenerator>();
|
||||||
@@ -91,8 +78,6 @@ namespace LibKubernetesGenerator
|
|||||||
{
|
{
|
||||||
#if GENERATE_BASIC
|
#if GENERATE_BASIC
|
||||||
generatorContext.RegisterPostInitializationOutput(ctx =>
|
generatorContext.RegisterPostInitializationOutput(ctx =>
|
||||||
{
|
|
||||||
lock (Execlock)
|
|
||||||
{
|
{
|
||||||
var (swagger, container) = BuildContainer();
|
var (swagger, container) = BuildContainer();
|
||||||
|
|
||||||
@@ -101,22 +86,16 @@ namespace LibKubernetesGenerator
|
|||||||
container.Resolve<ModelGenerator>().Generate(swagger, ctx);
|
container.Resolve<ModelGenerator>().Generate(swagger, ctx);
|
||||||
container.Resolve<ModelExtGenerator>().Generate(swagger, ctx);
|
container.Resolve<ModelExtGenerator>().Generate(swagger, ctx);
|
||||||
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, ctx);
|
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, ctx);
|
||||||
|
|
||||||
container.Resolve<ApiGenerator>().Generate(swagger, ctx);
|
container.Resolve<ApiGenerator>().Generate(swagger, ctx);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GENERATE_AUTOMAPPER
|
#if GENERATE_AUTOMAPPER
|
||||||
var automappersrc = generatorContext.CompilationProvider.Select((c, _) => c.SyntaxTrees.First(s => PathSuffixMath(s.FilePath, "AutoMapper/VersionConverter.cs")));
|
var automappersrc = generatorContext.CompilationProvider.Select((c, _) => c.SyntaxTrees.First(s => PathSuffixMath(s.FilePath, "AutoMapper/VersionConverter.cs")));
|
||||||
generatorContext.RegisterSourceOutput(automappersrc, (ctx, srctree) =>
|
generatorContext.RegisterSourceOutput(automappersrc, (ctx, srctree) =>
|
||||||
{
|
|
||||||
lock (Execlock)
|
|
||||||
{
|
{
|
||||||
var (swagger, container) = BuildContainer();
|
var (swagger, container) = BuildContainer();
|
||||||
|
|
||||||
container.Resolve<VersionConverterAutoMapperGenerator>().Generate(swagger, ctx, srctree);
|
container.Resolve<VersionConverterAutoMapperGenerator>().Generate(swagger, ctx, srctree);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<NoWarn>CA1812</NoWarn>
|
|
||||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||||
|
<PackageScribanIncludeSource>true</PackageScribanIncludeSource>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -16,15 +16,22 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Autofac" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
<!-- Scriban No Dependency -->
|
||||||
|
<PackageReference Include="Scriban" Version="5.9.1" IncludeAssets="Build"/>
|
||||||
|
|
||||||
|
<!-- CaseExtensions No Dependency -->
|
||||||
<PackageReference Include="CaseExtensions" Version="1.1.0" GeneratePathProperty="true" PrivateAssets="all" />
|
<PackageReference Include="CaseExtensions" Version="1.1.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
<PackageReference Include="NSwag.Core" Version="13.20.0" GeneratePathProperty="true" PrivateAssets="all" />
|
|
||||||
<PackageReference Include="Nustache" Version="1.16.0.10" GeneratePathProperty="true" PrivateAssets="all" NoWarn="NU1701" />
|
<!-- Autofac -->
|
||||||
<PackageReference Include="NJsonSchema" Version="10.9.0" GeneratePathProperty="true" PrivateAssets="all" />
|
<PackageReference Include="Autofac" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
|
|
||||||
|
<!-- NSwag -->
|
||||||
|
<PackageReference Include="NSwag.Core" Version="13.20.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
|
<PackageReference Include="NJsonSchema" Version="10.9.0" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" GeneratePathProperty="true" PrivateAssets="all" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
<PackageReference Include="Namotion.Reflection" Version="3.0.1" GeneratePathProperty="true" PrivateAssets="all" />
|
<PackageReference Include="Namotion.Reflection" Version="3.0.1" GeneratePathProperty="true" PrivateAssets="all" />
|
||||||
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" GeneratePathProperty="true" PrivateAssets="all" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -33,15 +40,16 @@
|
|||||||
|
|
||||||
<Target Name="GetDependencyTargetPaths">
|
<Target Name="GetDependencyTargetPaths">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGAutofac)\lib\netstandard2.0\Autofac.dll" IncludeRuntimeDependency="false" />
|
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGCaseExtensions)\lib\netstandard2.0\CaseExtensions.dll" IncludeRuntimeDependency="false" />
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGCaseExtensions)\lib\netstandard2.0\CaseExtensions.dll" IncludeRuntimeDependency="false" />
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNSwag_Core)\lib\netstandard2.0\NSwag.Core.dll" IncludeRuntimeDependency="false" />
|
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNustache)\lib\net20\Nustache.Core.dll" IncludeRuntimeDependency="false" />
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGAutofac)\lib\netstandard2.0\Autofac.dll" IncludeRuntimeDependency="false" />
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNJsonSchema)\lib\netstandard2.0\NJsonSchema.dll" IncludeRuntimeDependency="false" />
|
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGMicrosoft_Bcl_AsyncInterfaces)\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll" IncludeRuntimeDependency="false" />
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGMicrosoft_Bcl_AsyncInterfaces)\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll" IncludeRuntimeDependency="false" />
|
||||||
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGSystem_Diagnostics_DiagnosticSource)\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.dll" IncludeRuntimeDependency="false" />
|
||||||
|
|
||||||
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGNSwag_Core)\lib\netstandard2.0\NSwag.Core.dll" IncludeRuntimeDependency="false" />
|
||||||
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGNJsonSchema)\lib\netstandard2.0\NJsonSchema.dll" IncludeRuntimeDependency="false" />
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)\lib\netstandard1.0\Newtonsoft.Json.dll" IncludeRuntimeDependency="false" />
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGNewtonsoft_Json)\lib\netstandard1.0\Newtonsoft.Json.dll" IncludeRuntimeDependency="false" />
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGNamotion_Reflection)\lib\netstandard2.0\Namotion.Reflection.dll" IncludeRuntimeDependency="false" />
|
<TargetPathWithTargetPlatformMoniker Include="$(PKGNamotion_Reflection)\lib\netstandard2.0\Namotion.Reflection.dll" IncludeRuntimeDependency="false" />
|
||||||
<TargetPathWithTargetPlatformMoniker Include="$(PKGSystem_Diagnostics_DiagnosticSource)\lib\netstandard2.0\System.Diagnostics.DiagnosticSource.dll" IncludeRuntimeDependency="false" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,19 @@
|
|||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class MetaHelper : INustacheHelper
|
internal class MetaHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(GetGroup), GetGroup);
|
scriptObject.Import(nameof(GetGroup), GetGroup);
|
||||||
Helpers.Register(nameof(GetApiVersion), GetApiVersion);
|
scriptObject.Import(nameof(GetApiVersion), GetApiVersion);
|
||||||
Helpers.Register(nameof(GetKind), GetKind);
|
scriptObject.Import(nameof(GetKind), GetKind);
|
||||||
Helpers.Register(nameof(GetPathExpression), GetPathExpression);
|
scriptObject.Import(nameof(GetPathExpression), GetPathExpression);
|
||||||
}
|
|
||||||
|
|
||||||
public static void GetKind(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
context.Write(GetKind(arguments[0] as JsonSchema));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetKind(JsonSchema definition)
|
private static string GetKind(JsonSchema definition)
|
||||||
@@ -33,15 +24,6 @@ namespace LibKubernetesGenerator
|
|||||||
return groupVersionKind["kind"] as string;
|
return groupVersionKind["kind"] as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetGroup(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
context.Write(GetGroup(arguments[0] as JsonSchema));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetGroup(JsonSchema definition)
|
private static string GetGroup(JsonSchema definition)
|
||||||
{
|
{
|
||||||
var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"];
|
var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"];
|
||||||
@@ -50,16 +32,6 @@ namespace LibKubernetesGenerator
|
|||||||
return groupVersionKind["group"] as string;
|
return groupVersionKind["group"] as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetApiVersion(RenderContext context, IList<object> arguments,
|
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
context.Write(GetApiVersion(arguments[0] as JsonSchema));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetApiVersion(JsonSchema definition)
|
private static string GetApiVersion(JsonSchema definition)
|
||||||
{
|
{
|
||||||
var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"];
|
var groupVersionKindElements = (object[])definition.ExtensionData["x-kubernetes-group-version-kind"];
|
||||||
@@ -68,17 +40,6 @@ namespace LibKubernetesGenerator
|
|||||||
return groupVersionKind["version"] as string;
|
return groupVersionKind["version"] as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetPathExpression(RenderContext context, IList<object> arguments,
|
|
||||||
IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null &&
|
|
||||||
arguments[0] is OpenApiOperationDescription)
|
|
||||||
{
|
|
||||||
var operation = arguments[0] as OpenApiOperationDescription;
|
|
||||||
context.Write(GetPathExpression(operation));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetPathExpression(OpenApiOperationDescription operation)
|
private static string GetPathExpression(OpenApiOperationDescription operation)
|
||||||
{
|
{
|
||||||
var pathExpression = operation.Path;
|
var pathExpression = operation.Path;
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ namespace LibKubernetesGenerator
|
|||||||
internal class ModelExtGenerator
|
internal class ModelExtGenerator
|
||||||
{
|
{
|
||||||
private readonly ClassNameHelper classNameHelper;
|
private readonly ClassNameHelper classNameHelper;
|
||||||
|
private readonly ScriptObjectFactory scriptObjectFactory;
|
||||||
|
|
||||||
public ModelExtGenerator(ClassNameHelper classNameHelper)
|
public ModelExtGenerator(ClassNameHelper classNameHelper, ScriptObjectFactory scriptObjectFactory)
|
||||||
{
|
{
|
||||||
this.classNameHelper = classNameHelper;
|
this.classNameHelper = classNameHelper;
|
||||||
|
this.scriptObjectFactory = scriptObjectFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||||
@@ -25,7 +27,10 @@ namespace LibKubernetesGenerator
|
|||||||
&& d.ExtensionData.ContainsKey("x-kubernetes-group-version-kind")
|
&& d.ExtensionData.ContainsKey("x-kubernetes-group-version-kind")
|
||||||
&& !skippedTypes.Contains(classNameHelper.GetClassName(d)));
|
&& !skippedTypes.Contains(classNameHelper.GetClassName(d)));
|
||||||
|
|
||||||
context.RenderToContext("ModelExtensions.cs.template", definitions, "ModelExtensions.g.cs");
|
var sc = scriptObjectFactory.CreateScriptObject();
|
||||||
|
sc.SetValue("definitions", definitions, true);
|
||||||
|
|
||||||
|
context.RenderToContext("ModelExtensions.cs.template", sc, "ModelExtensions.g.cs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,29 @@ namespace LibKubernetesGenerator
|
|||||||
internal class ModelGenerator
|
internal class ModelGenerator
|
||||||
{
|
{
|
||||||
private readonly ClassNameHelper classNameHelper;
|
private readonly ClassNameHelper classNameHelper;
|
||||||
|
private readonly ScriptObjectFactory scriptObjectFactory;
|
||||||
|
|
||||||
public ModelGenerator(ClassNameHelper classNameHelper)
|
public ModelGenerator(ClassNameHelper classNameHelper, ScriptObjectFactory scriptObjectFactory)
|
||||||
{
|
{
|
||||||
this.classNameHelper = classNameHelper;
|
this.classNameHelper = classNameHelper;
|
||||||
|
this.scriptObjectFactory = scriptObjectFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||||
{
|
{
|
||||||
|
var sc = scriptObjectFactory.CreateScriptObject();
|
||||||
|
|
||||||
|
|
||||||
foreach (var kv in swagger.Definitions)
|
foreach (var kv in swagger.Definitions)
|
||||||
{
|
{
|
||||||
var def = kv.Value;
|
var def = kv.Value;
|
||||||
var clz = classNameHelper.GetClassNameForSchemaDefinition(def);
|
var clz = classNameHelper.GetClassNameForSchemaDefinition(def);
|
||||||
context.RenderToContext(
|
|
||||||
"Model.cs.template",
|
sc.SetValue("clz", clz, true);
|
||||||
new { clz, def, properties = def.Properties.Values },
|
sc.SetValue("def", def, true);
|
||||||
$"Models_{clz}.g.cs");
|
sc.SetValue("properties", def.Properties.Values, true);
|
||||||
|
|
||||||
|
context.RenderToContext("Model.cs.template", sc, $"Models_{clz}.g.cs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class ParamHelper : INustacheHelper
|
internal class ParamHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly GeneralNameHelper generalNameHelper;
|
private readonly GeneralNameHelper generalNameHelper;
|
||||||
private readonly TypeHelper typeHelper;
|
private readonly TypeHelper typeHelper;
|
||||||
@@ -17,26 +17,14 @@ namespace LibKubernetesGenerator
|
|||||||
this.typeHelper = typeHelper;
|
this.typeHelper = typeHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(IfParamContains), IfParamContains);
|
scriptObject.Import(nameof(GetModelCtorParam), new Func<JsonSchema, string>(GetModelCtorParam));
|
||||||
Helpers.Register(nameof(IfParamDoesNotContain), IfParamDoesNotContain);
|
scriptObject.Import(nameof(IfParamContains), IfParamContains);
|
||||||
Helpers.Register(nameof(GetModelCtorParam), GetModelCtorParam);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IfParamContains(RenderContext context, IList<object> arguments,
|
public static bool IfParamContains(OpenApiOperation operation, string name)
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var operation = arguments?.FirstOrDefault() as OpenApiOperation;
|
|
||||||
if (operation != null)
|
|
||||||
{
|
|
||||||
string name = null;
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
name = arguments[1] as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var found = false;
|
var found = false;
|
||||||
|
|
||||||
foreach (var param in operation.Parameters)
|
foreach (var param in operation.Parameters)
|
||||||
@@ -48,53 +36,12 @@ namespace LibKubernetesGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
return found;
|
||||||
{
|
|
||||||
fn(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IfParamDoesNotContain(RenderContext context, IList<object> arguments,
|
public string GetModelCtorParam(JsonSchema schema)
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var operation = arguments?.FirstOrDefault() as OpenApiOperation;
|
return string.Join(", ", schema.Properties.Values
|
||||||
if (operation != null)
|
|
||||||
{
|
|
||||||
string name = null;
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
name = arguments[1] as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var found = false;
|
|
||||||
|
|
||||||
foreach (var param in operation.Parameters)
|
|
||||||
{
|
|
||||||
if (param.Name == name)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
{
|
|
||||||
fn(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetModelCtorParam(RenderContext context, IList<object> arguments,
|
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
var schema = arguments[0] as JsonSchema;
|
|
||||||
|
|
||||||
if (schema != null)
|
|
||||||
{
|
|
||||||
context.Write(string.Join(", ", schema.Properties.Values
|
|
||||||
.OrderBy(p => !p.IsRequired)
|
.OrderBy(p => !p.IsRequired)
|
||||||
.Select(p =>
|
.Select(p =>
|
||||||
{
|
{
|
||||||
@@ -107,8 +54,7 @@ namespace LibKubernetesGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sp;
|
return sp;
|
||||||
})));
|
}));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class PluralHelper : INustacheHelper
|
internal class PluralHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, string> _classNameToPluralMap;
|
private readonly Dictionary<string, string> _classNameToPluralMap;
|
||||||
private readonly ClassNameHelper classNameHelper;
|
private readonly ClassNameHelper classNameHelper;
|
||||||
@@ -23,26 +23,9 @@ namespace LibKubernetesGenerator
|
|||||||
_classNameToPluralMap = InitClassNameToPluralMap(swagger);
|
_classNameToPluralMap = InitClassNameToPluralMap(swagger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(GetPlural), GetPlural);
|
scriptObject.Import(nameof(GetPlural), new Func<JsonSchema, string>(GetPlural));
|
||||||
}
|
|
||||||
|
|
||||||
public void GetPlural(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchema)
|
|
||||||
{
|
|
||||||
var plural = GetPlural(arguments[0] as JsonSchema);
|
|
||||||
if (plural != null)
|
|
||||||
{
|
|
||||||
context.Write($"\"{plural}\"");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Write("null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPlural(JsonSchema definition)
|
public string GetPlural(JsonSchema definition)
|
||||||
|
|||||||
26
src/LibKubernetesGenerator/ScriptObjectFactory.cs
Normal file
26
src/LibKubernetesGenerator/ScriptObjectFactory.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Scriban.Runtime;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace LibKubernetesGenerator;
|
||||||
|
|
||||||
|
internal class ScriptObjectFactory
|
||||||
|
{
|
||||||
|
private readonly List<IScriptObjectHelper> scriptObjectHelpers;
|
||||||
|
|
||||||
|
public ScriptObjectFactory(IEnumerable<IScriptObjectHelper> scriptObjectHelpers)
|
||||||
|
{
|
||||||
|
this.scriptObjectHelpers = scriptObjectHelpers.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScriptObject CreateScriptObject()
|
||||||
|
{
|
||||||
|
var scriptObject = new ScriptObject();
|
||||||
|
foreach (var helper in scriptObjectHelpers)
|
||||||
|
{
|
||||||
|
helper.RegisterHelper(scriptObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return scriptObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class StringHelpers : INustacheHelper
|
internal class StringHelpers : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly GeneralNameHelper generalNameHelper;
|
private readonly GeneralNameHelper generalNameHelper;
|
||||||
|
|
||||||
@@ -18,21 +19,24 @@ namespace LibKubernetesGenerator
|
|||||||
this.generalNameHelper = generalNameHelper;
|
this.generalNameHelper = generalNameHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(ToXmlDoc), ToXmlDoc);
|
scriptObject.Import(nameof(ToXmlDoc), new Func<string, string>(ToXmlDoc));
|
||||||
Helpers.Register(nameof(ToInterpolationPathString), ToInterpolationPathString);
|
scriptObject.Import(nameof(ToInterpolationPathString), ToInterpolationPathString);
|
||||||
Helpers.Register(nameof(IfGroupPathParamContainsGroup), IfGroupPathParamContainsGroup);
|
scriptObject.Import(nameof(IfGroupPathParamContainsGroup), IfGroupPathParamContainsGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToXmlDoc(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
public static string ToXmlDoc(string arg)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is string)
|
if (arg == null)
|
||||||
{
|
{
|
||||||
var first = true;
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
using (var reader = new StringReader(arguments[0] as string))
|
var first = true;
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
using (var reader = new StringReader(arg))
|
||||||
{
|
{
|
||||||
string line = null;
|
string line = null;
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
@@ -41,19 +45,20 @@ namespace LibKubernetesGenerator
|
|||||||
{
|
{
|
||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
context.Write("\n");
|
sb.Append("\n");
|
||||||
context.Write(" /// ");
|
sb.Append(" /// ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Write(SecurityElement.Escape(wline));
|
sb.Append(SecurityElement.Escape(wline));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> WordWrap(string text, int width)
|
private static IEnumerable<string> WordWrap(string text, int width)
|
||||||
@@ -91,24 +96,14 @@ namespace LibKubernetesGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToInterpolationPathString(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
public string ToInterpolationPathString(string arg)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var p = arguments?.FirstOrDefault() as string;
|
return Regex.Replace(arg, "{(.+?)}", (m) => "{" + generalNameHelper.GetDotNetName(m.Groups[1].Value) + "}");
|
||||||
if (p != null)
|
|
||||||
{
|
|
||||||
context.Write(Regex.Replace(p, "{(.+?)}", (m) => "{" + generalNameHelper.GetDotNetName(m.Groups[1].Value) + "}"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IfGroupPathParamContainsGroup(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
public static bool IfGroupPathParamContainsGroup(string arg)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var p = arguments?.FirstOrDefault() as string;
|
return arg.StartsWith("apis/{group}");
|
||||||
if (p?.StartsWith("apis/{group}") == true)
|
|
||||||
{
|
|
||||||
fn(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
using NJsonSchema;
|
using NJsonSchema;
|
||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class TypeHelper : INustacheHelper
|
internal class TypeHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
private readonly ClassNameHelper classNameHelper;
|
private readonly ClassNameHelper classNameHelper;
|
||||||
|
|
||||||
@@ -16,57 +14,13 @@ namespace LibKubernetesGenerator
|
|||||||
this.classNameHelper = classNameHelper;
|
this.classNameHelper = classNameHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(GetDotNetType), GetDotNetType);
|
scriptObject.Import(nameof(GetDotNetType), new Func<JsonSchemaProperty, string>(GetDotNetType));
|
||||||
Helpers.Register(nameof(GetReturnType), GetReturnType);
|
scriptObject.Import(nameof(GetDotNetTypeOpenApiParameter), new Func<OpenApiParameter, string>(GetDotNetTypeOpenApiParameter));
|
||||||
Helpers.Register(nameof(IfReturnType), IfReturnType);
|
scriptObject.Import(nameof(GetReturnType), new Func<OpenApiOperation, string, string>(GetReturnType));
|
||||||
Helpers.Register(nameof(IfType), IfType);
|
scriptObject.Import(nameof(IfReturnType), new Func<OpenApiOperation, string, bool>(IfReturnType));
|
||||||
}
|
scriptObject.Import(nameof(IfType), new Func<JsonSchemaProperty, string, bool>(IfType));
|
||||||
|
|
||||||
public void GetDotNetType(RenderContext context, IList<object> arguments,
|
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is OpenApiParameter)
|
|
||||||
{
|
|
||||||
var parameter = arguments[0] as OpenApiParameter;
|
|
||||||
|
|
||||||
if (parameter.Schema?.Reference != null)
|
|
||||||
{
|
|
||||||
context.Write(classNameHelper.GetClassNameForSchemaDefinition(parameter.Schema.Reference));
|
|
||||||
}
|
|
||||||
else if (parameter.Schema != null)
|
|
||||||
{
|
|
||||||
context.Write(GetDotNetType(parameter.Schema.Type, parameter.Name, parameter.IsRequired,
|
|
||||||
parameter.Schema.Format));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Write(GetDotNetType(parameter.Type, parameter.Name, parameter.IsRequired,
|
|
||||||
parameter.Format));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is JsonSchemaProperty)
|
|
||||||
{
|
|
||||||
var property = arguments[0] as JsonSchemaProperty;
|
|
||||||
context.Write(GetDotNetType(property));
|
|
||||||
}
|
|
||||||
else if (arguments != null && arguments.Count > 2 && arguments[0] != null && arguments[1] != null &&
|
|
||||||
arguments[2] != null && arguments[0] is JsonObjectType && arguments[1] is string &&
|
|
||||||
arguments[2] is bool)
|
|
||||||
{
|
|
||||||
context.Write(GetDotNetType((JsonObjectType)arguments[0], (string)arguments[1], (bool)arguments[2],
|
|
||||||
(string)arguments[3]));
|
|
||||||
}
|
|
||||||
else if (arguments != null && arguments.Count > 0 && arguments[0] != null)
|
|
||||||
{
|
|
||||||
context.Write($"ERROR: Expected OpenApiParameter but got {arguments[0].GetType().FullName}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Write("ERROR: Expected a OpenApiParameter argument but got none.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDotNetType(JsonObjectType jsonType, string name, bool required, string format)
|
private string GetDotNetType(JsonObjectType jsonType, string name, bool required, string format)
|
||||||
@@ -204,20 +158,21 @@ namespace LibKubernetesGenerator
|
|||||||
return GetDotNetType(p.Type, p.Name, p.IsRequired, p.Format);
|
return GetDotNetType(p.Type, p.Name, p.IsRequired, p.Format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetReturnType(RenderContext context, IList<object> arguments,
|
public string GetDotNetTypeOpenApiParameter(OpenApiParameter parameter)
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var operation = arguments?.FirstOrDefault() as OpenApiOperation;
|
if (parameter.Schema?.Reference != null)
|
||||||
if (operation != null)
|
|
||||||
{
|
{
|
||||||
string style = null;
|
return classNameHelper.GetClassNameForSchemaDefinition(parameter.Schema.Reference);
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
style = arguments[1] as string;
|
|
||||||
}
|
}
|
||||||
|
else if (parameter.Schema != null)
|
||||||
context.Write(GetReturnType(operation, style));
|
{
|
||||||
|
return (GetDotNetType(parameter.Schema.Type, parameter.Name, parameter.IsRequired,
|
||||||
|
parameter.Schema.Format));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (GetDotNetType(parameter.Type, parameter.Name, parameter.IsRequired,
|
||||||
|
parameter.Format));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,57 +250,38 @@ namespace LibKubernetesGenerator
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IfReturnType(RenderContext context, IList<object> arguments,
|
public bool IfReturnType(OpenApiOperation operation, string type)
|
||||||
IDictionary<string, object> options,
|
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var operation = arguments?.FirstOrDefault() as OpenApiOperation;
|
|
||||||
if (operation != null)
|
|
||||||
{
|
|
||||||
string type = null;
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
type = arguments[1] as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rt = GetReturnType(operation, "void");
|
var rt = GetReturnType(operation, "void");
|
||||||
if (type == "any" && rt != "void")
|
if (type == "any" && rt != "void")
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
}
|
||||||
else if (string.Equals(type, rt.ToLower(), StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(type, rt.ToLower(), StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
}
|
||||||
else if (type == "obj" && rt != "void" && rt != "Stream")
|
else if (type == "obj" && rt != "void" && rt != "Stream")
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IfType(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
return false;
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
var property = arguments?.FirstOrDefault() as JsonSchemaProperty;
|
|
||||||
if (property != null)
|
|
||||||
{
|
|
||||||
string type = null;
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
type = arguments[1] as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IfType(JsonSchemaProperty property, string type)
|
||||||
|
{
|
||||||
if (type == "object" && property.Reference != null && !property.IsArray &&
|
if (type == "object" && property.Reference != null && !property.IsArray &&
|
||||||
property.AdditionalPropertiesSchema == null)
|
property.AdditionalPropertiesSchema == null)
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
}
|
||||||
else if (type == "objectarray" && property.IsArray && property.Item?.Reference != null)
|
else if (type == "objectarray" && property.IsArray && property.Item?.Reference != null)
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +1,30 @@
|
|||||||
using NSwag;
|
using NSwag;
|
||||||
using Nustache.Core;
|
using Scriban.Runtime;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace LibKubernetesGenerator
|
namespace LibKubernetesGenerator
|
||||||
{
|
{
|
||||||
internal class UtilHelper : INustacheHelper
|
internal class UtilHelper : IScriptObjectHelper
|
||||||
{
|
{
|
||||||
public void RegisterHelper()
|
public void RegisterHelper(ScriptObject scriptObject)
|
||||||
{
|
{
|
||||||
Helpers.Register(nameof(IfKindIs), IfKindIs);
|
scriptObject.Import(nameof(IfKindIs), IfKindIs);
|
||||||
Helpers.Register(nameof(IfListNotEmpty), IfListNotEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IfKindIs(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
public static bool IfKindIs(OpenApiParameter parameter, string kind)
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
{
|
||||||
var parameter = arguments?.FirstOrDefault() as OpenApiParameter;
|
|
||||||
if (parameter != null)
|
if (parameter != null)
|
||||||
{
|
{
|
||||||
string kind = null;
|
|
||||||
if (arguments.Count > 1)
|
|
||||||
{
|
|
||||||
kind = arguments[1] as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == "query" && parameter.Kind == OpenApiParameterKind.Query)
|
if (kind == "query" && parameter.Kind == OpenApiParameterKind.Query)
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
}
|
||||||
else if (kind == "path" && parameter.Kind == OpenApiParameterKind.Path)
|
else if (kind == "path" && parameter.Kind == OpenApiParameterKind.Path)
|
||||||
{
|
{
|
||||||
fn(null);
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IfListNotEmpty(RenderContext context, IList<object> arguments, IDictionary<string, object> options,
|
return false;
|
||||||
RenderBlock fn, RenderBlock inverse)
|
|
||||||
{
|
|
||||||
var parameter = arguments?.FirstOrDefault() as ObservableCollection<OpenApiParameter>;
|
|
||||||
if (parameter?.Any() == true)
|
|
||||||
{
|
|
||||||
fn(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace k8s;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract partial class AbstractKubernetes
|
public abstract partial class AbstractKubernetes
|
||||||
{
|
{
|
||||||
{{#.}}
|
{{for group in groups}}
|
||||||
public I{{.}}Operations {{.}} => this;
|
public I{{group}}Operations {{group}} => this;
|
||||||
{{/.}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace k8s;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial interface IBasicKubernetes
|
public partial interface IBasicKubernetes
|
||||||
{
|
{
|
||||||
{{#.}}
|
{{for group in groups}}
|
||||||
I{{.}}Operations {{.}} { get; }
|
I{{group}}Operations {{group}} { get; }
|
||||||
{{/.}}
|
{{end}}
|
||||||
}
|
}
|
||||||
@@ -10,50 +10,50 @@ namespace k8s;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial interface I{{name}}Operations
|
public partial interface I{{name}}Operations
|
||||||
{
|
{
|
||||||
{{#apis}}
|
{{for api in apis }}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc parameter.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
/// <param name="customHeaders">
|
/// <param name="customHeaders">
|
||||||
/// The headers that will be added to request.
|
/// The headers that will be added to request.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="cancellationToken">
|
/// <param name="cancellationToken">
|
||||||
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
||||||
/// </param>
|
/// </param>
|
||||||
Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
|
Task<HttpOperationResponse{{GetReturnType api.operation "<>"}}> {{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName . "true"}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}},
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
|
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
|
||||||
CancellationToken cancellationToken = default);
|
CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
{{#IfReturnType operation "object"}}
|
{{if IfReturnType api.operation "object"}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc parameter.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
/// <param name="customHeaders">
|
/// <param name="customHeaders">
|
||||||
/// The headers that will be added to request.
|
/// The headers that will be added to request.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="cancellationToken">
|
/// <param name="cancellationToken">
|
||||||
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
||||||
/// </param>
|
/// </param>
|
||||||
Task<HttpOperationResponse<T>> {{GetMethodName operation "WithHttpMessagesAsync"}}<T>(
|
Task<HttpOperationResponse<T>> {{GetMethodName api.operation "WithHttpMessagesAsync"}}<T>(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName . "true"}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}},
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
|
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders = null,
|
||||||
CancellationToken cancellationToken = default);
|
CancellationToken cancellationToken = default);
|
||||||
{{/IfReturnType operation "object"}}
|
{{ end }}
|
||||||
|
|
||||||
{{/apis}}
|
{{ end }}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,25 +22,26 @@ namespace k8s.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the {{GetClassName def}} class.
|
/// Initializes a new instance of the {{GetClassName def}} class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
{{#properties}}
|
{{ for property in properties }}
|
||||||
{{#isRequired}}
|
{{ if property.IsRequired }}
|
||||||
/// <param name="{{GetDotNetName name "fieldctor"}}">
|
/// <param name="{{GetDotNetName property.name "fieldctor"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc property.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/isRequired}}
|
{{ end }}
|
||||||
{{/properties}}
|
{{ end }}
|
||||||
{{#properties}}
|
|
||||||
{{^isRequired}}
|
{{ for property in properties }}
|
||||||
/// <param name="{{GetDotNetName name "fieldctor"}}">
|
{{ if !property.IsRequired }}
|
||||||
/// {{ToXmlDoc description}}
|
/// <param name="{{GetDotNetName property.name "fieldctor"}}">
|
||||||
|
/// {{ToXmlDoc property.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/isRequired}}
|
{{ end }}
|
||||||
{{/properties}}
|
{{ end }}
|
||||||
public {{clz}}({{GetModelCtorParam def}})
|
public {{clz}}({{GetModelCtorParam def}})
|
||||||
{
|
{
|
||||||
{{#properties}}
|
{{ for property in properties }}
|
||||||
{{GetDotNetName name "field"}} = {{GetDotNetName name "fieldctor"}};
|
{{GetDotNetName property.name "field"}} = {{GetDotNetName property.name "fieldctor"}};
|
||||||
{{/properties}}
|
{{ end }}
|
||||||
CustomInit();
|
CustomInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,14 +49,14 @@ namespace k8s.Models
|
|||||||
/// An initialization method that performs custom operations like setting defaults
|
/// An initialization method that performs custom operations like setting defaults
|
||||||
/// </summary>
|
/// </summary>
|
||||||
partial void CustomInit();
|
partial void CustomInit();
|
||||||
{{#properties}}
|
|
||||||
|
|
||||||
|
{{ for property in properties }}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc property.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("{{name}}")]
|
[JsonPropertyName("{{property.name}}")]
|
||||||
public {{GetDotNetType .}} {{GetDotNetName name "field"}} { get; set; }
|
public {{GetDotNetType property}} {{GetDotNetName property.name "field"}} { get; set; }
|
||||||
{{/properties}}
|
{{ end }}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Validate the object.
|
/// Validate the object.
|
||||||
@@ -65,29 +66,32 @@ namespace k8s.Models
|
|||||||
/// </exception>
|
/// </exception>
|
||||||
public virtual void Validate()
|
public virtual void Validate()
|
||||||
{
|
{
|
||||||
{{#properties}}
|
{{ for property in properties }}
|
||||||
{{#IfType . "object"}}
|
{{if IfType property "object" }}
|
||||||
{{#isRequired}}
|
{{ if property.IsRequired }}
|
||||||
if ({{GetDotNetName name "field"}} == null)
|
if ({{GetDotNetName property.name "field"}} == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("{{GetDotNetName name "field"}}");
|
throw new ArgumentNullException("{{GetDotNetName property.name "field"}}");
|
||||||
}
|
}
|
||||||
{{/isRequired}}
|
{{ end }}
|
||||||
{{/IfType . "object"}}
|
{{ end }}
|
||||||
{{/properties}}
|
|
||||||
{{#properties}}
|
{{ end }}
|
||||||
{{#IfType . "object"}}
|
|
||||||
{{GetDotNetName name "field"}}?.Validate();
|
{{ for property in properties }}
|
||||||
{{/IfType . "object"}}
|
{{if IfType property "object" }}
|
||||||
{{#IfType . "objectarray"}}
|
{{GetDotNetName property.name "field"}}?.Validate();
|
||||||
if ({{GetDotNetName name "field"}} != null){
|
{{ end }}
|
||||||
foreach(var obj in {{GetDotNetName name "field"}})
|
|
||||||
|
{{if IfType property "objectarray" }}
|
||||||
|
if ({{GetDotNetName property.name "field"}} != null){
|
||||||
|
foreach(var obj in {{GetDotNetName property.name "field"}})
|
||||||
{
|
{
|
||||||
obj.Validate();
|
obj.Validate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/IfType . "objectarray"}}
|
{{ end }}
|
||||||
{{/properties}}
|
{{ end }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,25 +4,24 @@
|
|||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
namespace k8s.Models
|
namespace k8s.Models
|
||||||
{
|
{
|
||||||
{{#.}}
|
{{ for definition in definitions }}
|
||||||
[KubernetesEntity(Group=KubeGroup, Kind=KubeKind, ApiVersion=KubeApiVersion, PluralName=KubePluralName)]
|
[KubernetesEntity(Group=KubeGroup, Kind=KubeKind, ApiVersion=KubeApiVersion, PluralName=KubePluralName)]
|
||||||
public partial class {{GetClassName . }} : {{GetInterfaceName . }}
|
public partial class {{ GetClassName definition }} : {{ GetInterfaceName definition }}
|
||||||
{
|
{
|
||||||
public const string KubeApiVersion = "{{GetApiVersion . }}";
|
public const string KubeApiVersion = "{{ GetApiVersion definition }}";
|
||||||
public const string KubeKind = "{{GetKind . }}";
|
public const string KubeKind = "{{ GetKind definition }}";
|
||||||
public const string KubeGroup = "{{GetGroup . }}";
|
public const string KubeGroup = "{{ GetGroup definition }}";
|
||||||
public const string KubePluralName = {{GetPlural . }};
|
public const string KubePluralName = "{{ GetPlural definition }}";
|
||||||
}
|
}
|
||||||
|
{{ end }}
|
||||||
{{/.}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NET8_0_OR_GREATER
|
#if NET8_0_OR_GREATER
|
||||||
namespace k8s
|
namespace k8s
|
||||||
{
|
{
|
||||||
{{#.}}
|
{{ for definition in definitions }}
|
||||||
[JsonSerializable(typeof({{GetClassName . }}))]
|
[JsonSerializable(typeof({{ GetClassName definition }}))]
|
||||||
{{/.}}
|
{{ end }}
|
||||||
internal partial class SourceGenerationContext : JsonSerializerContext
|
internal partial class SourceGenerationContext : JsonSerializerContext
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,139 +8,137 @@ namespace k8s;
|
|||||||
|
|
||||||
public partial class AbstractKubernetes : I{{name}}Operations
|
public partial class AbstractKubernetes : I{{name}}Operations
|
||||||
{
|
{
|
||||||
{{#apis}}
|
{{for api in apis }}
|
||||||
{{#IfReturnType operation "void"}}
|
{{if IfReturnType api.operation "void"}}
|
||||||
private async Task<HttpOperationResponse> I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
private async Task<HttpOperationResponse> I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{/IfReturnType operation "void"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "obj"}}
|
{{if IfReturnType api.operation "obj"}}
|
||||||
private async Task<HttpOperationResponse<T>> I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}<T>(
|
private async Task<HttpOperationResponse<T>> I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}<T>(
|
||||||
{{/IfReturnType operation "obj"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "stream"}}
|
{{if IfReturnType api.operation "stream"}}
|
||||||
private async Task<HttpOperationResponse<Stream>> I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
private async Task<HttpOperationResponse<Stream>> I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{/IfReturnType operation "stream"}}
|
{{end}}
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName .}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||||
cts.CancelAfter(HttpClientTimeout);
|
cts.CancelAfter(HttpClientTimeout);
|
||||||
{{#IfParamContains operation "watch"}}
|
{{if IfParamContains api.operation "watch"}}
|
||||||
if (watch == true)
|
if (watch == true)
|
||||||
{
|
{
|
||||||
cts.CancelAfter(Timeout.InfiniteTimeSpan);
|
cts.CancelAfter(Timeout.InfiniteTimeSpan);
|
||||||
}
|
}
|
||||||
{{/IfParamContains operation "watch"}}
|
{{end}}
|
||||||
cancellationToken = cts.Token;
|
cancellationToken = cts.Token;
|
||||||
|
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{#isRequired}}
|
{{ if parameter.IsRequired}}
|
||||||
if ({{GetDotNetName name}} == null)
|
if ({{GetDotNetName parameter.name}} == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("{{GetDotNetName name}}");
|
throw new ArgumentNullException("{{GetDotNetName parameter.name}}");
|
||||||
}
|
}
|
||||||
{{/isRequired}}
|
{{end}}
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
|
|
||||||
// Construct URL
|
// Construct URL
|
||||||
var url = $"{{ToInterpolationPathString path}}";
|
var url = $"{{ToInterpolationPathString api.path}}";
|
||||||
{{#IfGroupPathParamContainsGroup path}}
|
{{if IfGroupPathParamContainsGroup api.path}}
|
||||||
url = url.Replace("apis//", "api/");
|
url = url.Replace("apis//", "api/");
|
||||||
{{/IfGroupPathParamContainsGroup}}
|
{{end}}
|
||||||
{{#IfListNotEmpty operation.parameters}}
|
{{if (array.size api.operation.parameters) > 0}}
|
||||||
var q = new QueryBuilder();
|
var q = new QueryBuilder();
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{#IfKindIs . "query"}}
|
{{if IfKindIs parameter "query"}}
|
||||||
q.Append("{{name}}", {{GetDotNetName name}});
|
q.Append("{{parameter.name}}", {{GetDotNetName parameter.name}});
|
||||||
{{/IfKindIs . "query"}}
|
{{end}}
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
url += q.ToString();
|
url += q.ToString();
|
||||||
{{/IfListNotEmpty operation.parameters}}
|
{{end}}
|
||||||
|
|
||||||
// Create HTTP transport
|
// Create HTTP transport
|
||||||
{{#IfParamContains operation "body"}}
|
{{if IfParamContains api.operation "body"}}
|
||||||
var httpResponse = await SendRequest(url, HttpMethods.{{Method}}, customHeaders, body, cancellationToken);
|
var httpResponse = await SendRequest(url, HttpMethods.{{api.method}}, customHeaders, body, cancellationToken);
|
||||||
{{/IfParamContains operation "body"}}
|
{{ else }}
|
||||||
{{#IfParamDoesNotContain operation "body"}}
|
var httpResponse = await SendRequest<object>(url, HttpMethods.{{api.method}}, customHeaders, null, cancellationToken);
|
||||||
var httpResponse = await SendRequest<object>(url, HttpMethods.{{Method}}, customHeaders, null, cancellationToken);
|
{{end}}
|
||||||
{{/IfParamDoesNotContain operation "body"}}
|
|
||||||
// Create Result
|
// Create Result
|
||||||
var httpRequest = httpResponse.RequestMessage;
|
var httpRequest = httpResponse.RequestMessage;
|
||||||
{{#IfReturnType operation "void"}}
|
{{if IfReturnType api.operation "void"}}
|
||||||
HttpOperationResponse result = new HttpOperationResponse() { Request = httpRequest, Response = httpResponse };
|
HttpOperationResponse result = new HttpOperationResponse() { Request = httpRequest, Response = httpResponse };
|
||||||
{{/IfReturnType operation "void"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "obj"}}
|
{{if IfReturnType api.operation "obj"}}
|
||||||
var result = await CreateResultAsync<T>(
|
var result = await CreateResultAsync<T>(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
httpResponse,
|
httpResponse,
|
||||||
{{#IfParamContains operation "watch"}}
|
{{if IfParamContains api.operation "watch"}}
|
||||||
watch,
|
watch,
|
||||||
{{/IfParamContains operation "watch"}}
|
{{else}}
|
||||||
{{#IfParamDoesNotContain operation "watch"}}
|
|
||||||
false,
|
false,
|
||||||
{{/IfParamDoesNotContain operation "watch"}}
|
{{end}}
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
{{/IfReturnType operation "obj"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "stream"}}
|
{{if IfReturnType api.operation "stream"}}
|
||||||
var result = new HttpOperationResponse<Stream>() {
|
var result = new HttpOperationResponse<Stream>() {
|
||||||
Request = httpRequest,
|
Request = httpRequest,
|
||||||
Response = httpResponse,
|
Response = httpResponse,
|
||||||
Body = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
|
Body = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
|
||||||
{{/IfReturnType operation "stream"}}
|
{{end}}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> I{{name}}Operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
async Task<HttpOperationResponse{{GetReturnType api.operation "<>"}}> I{{name}}Operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName .}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
{{#IfReturnType operation "void"}}
|
{{if IfReturnType api.operation "void"}}
|
||||||
return await I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
return await I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
customHeaders,
|
customHeaders,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
{{/IfReturnType operation "void"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "obj"}}
|
{{if IfReturnType api.operation "obj"}}
|
||||||
return await I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}{{GetReturnType operation "<>"}}(
|
return await I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}{{GetReturnType api.operation "<>"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
customHeaders,
|
customHeaders,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
{{/IfReturnType operation "obj"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "stream"}}
|
{{if IfReturnType api.operation "stream"}}
|
||||||
return await I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
return await I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
customHeaders,
|
customHeaders,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
{{/IfReturnType operation "stream"}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#IfReturnType operation "object"}}
|
{{if IfReturnType api.operation "object"}}
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
async Task<HttpOperationResponse<T>> I{{name}}Operations.{{GetMethodName operation "WithHttpMessagesAsync"}}<T>(
|
async Task<HttpOperationResponse<T>> I{{name}}Operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}<T>(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName .}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await I{{name}}Operations_{{GetMethodName operation "WithHttpMessagesAsync"}}<T>(
|
return await I{{name}}Operations_{{GetMethodName api.operation "WithHttpMessagesAsync"}}<T>(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
customHeaders,
|
customHeaders,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
{{/IfReturnType operation "object"}}
|
{{end}}
|
||||||
{{/apis}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,148 +11,148 @@ namespace k8s;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static partial class {{name}}OperationsExtensions
|
public static partial class {{name}}OperationsExtensions
|
||||||
{
|
{
|
||||||
{{#apis}}
|
{{for api in apis }}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name='operations'>
|
/// <param name='operations'>
|
||||||
/// The operations group for this extension method.
|
/// The operations group for this extension method.
|
||||||
/// </param>
|
/// </param>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc api.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
public static {{GetReturnType operation "void"}} {{GetMethodName operation ""}}(
|
public static {{GetReturnType api.operation "void"}} {{GetMethodName api.operation ""}}(
|
||||||
this I{{name}}Operations operations
|
this I{{name}}Operations operations
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
,{{GetDotNetType .}} {{GetDotNetName . "true"}}
|
,{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}}
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
{{GetReturnType operation "return"}} operations.{{GetMethodName operation "Async"}}(
|
{{GetReturnType api.operation "return"}} operations.{{GetMethodName api.operation "Async"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
CancellationToken.None
|
CancellationToken.None
|
||||||
).GetAwaiter().GetResult();
|
).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#IfReturnType operation "object"}}
|
{{if IfReturnType api.operation "object"}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name='operations'>
|
/// <param name='operations'>
|
||||||
/// The operations group for this extension method.
|
/// The operations group for this extension method.
|
||||||
/// </param>
|
/// </param>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc parameter.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
public static T {{GetMethodName operation ""}}<T>(
|
public static T {{GetMethodName api.operation ""}}<T>(
|
||||||
this I{{name}}Operations operations
|
this I{{name}}Operations operations
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
,{{GetDotNetType .}} {{GetDotNetName . "true"}}
|
,{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}}
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return operations.{{GetMethodName operation "Async"}}<T>(
|
return operations.{{GetMethodName api.operation "Async"}}<T>(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
CancellationToken.None
|
CancellationToken.None
|
||||||
).GetAwaiter().GetResult();
|
).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
{{/IfReturnType operation "object"}}
|
{{end}}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name='operations'>
|
/// <param name='operations'>
|
||||||
/// The operations group for this extension method.
|
/// The operations group for this extension method.
|
||||||
/// </param>
|
/// </param>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc parameter.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
/// <param name="cancellationToken">
|
/// <param name="cancellationToken">
|
||||||
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
||||||
/// </param>
|
/// </param>
|
||||||
public static async Task{{GetReturnType operation "<>"}} {{GetMethodName operation "Async"}}(
|
public static async Task{{GetReturnType api.operation "<>"}} {{GetMethodName api.operation "Async"}}(
|
||||||
this I{{name}}Operations operations,
|
this I{{name}}Operations operations,
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName . "true"}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}},
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
CancellationToken cancellationToken = default(CancellationToken))
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
{{#IfReturnType operation "stream"}}
|
{{if IfReturnType api.operation "stream"}}
|
||||||
var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
var _result = await operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
null,
|
null,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
_result.Request.Dispose();
|
_result.Request.Dispose();
|
||||||
{{GetReturnType operation "_result.Body"}};
|
{{GetReturnType api.operation "_result.Body"}};
|
||||||
{{/IfReturnType operation "stream"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "obj"}}
|
{{if IfReturnType api.operation "obj"}}
|
||||||
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
using (var _result = await operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
null,
|
null,
|
||||||
cancellationToken).ConfigureAwait(false))
|
cancellationToken).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
{{GetReturnType operation "_result.Body"}};
|
{{GetReturnType api.operation "_result.Body"}};
|
||||||
}
|
}
|
||||||
{{/IfReturnType operation "obj"}}
|
{{end}}
|
||||||
{{#IfReturnType operation "void"}}
|
{{if IfReturnType api.operation "void"}}
|
||||||
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
|
using (var _result = await operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
null,
|
null,
|
||||||
cancellationToken).ConfigureAwait(false))
|
cancellationToken).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
{{/IfReturnType operation "void"}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#IfReturnType operation "object"}}
|
{{if IfReturnType api.operation "object"}}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// {{ToXmlDoc operation.description}}
|
/// {{ToXmlDoc api.operation.description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name='operations'>
|
/// <param name='operations'>
|
||||||
/// The operations group for this extension method.
|
/// The operations group for this extension method.
|
||||||
/// </param>
|
/// </param>
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
/// <param name="{{GetDotNetName .}}">
|
/// <param name="{{GetDotNetNameOpenApiParameter parameter "false"}}">
|
||||||
/// {{ToXmlDoc description}}
|
/// {{ToXmlDoc parameter.description}}
|
||||||
/// </param>
|
/// </param>
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
/// <param name="cancellationToken">
|
/// <param name="cancellationToken">
|
||||||
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
/// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
|
||||||
/// </param>
|
/// </param>
|
||||||
public static async Task<T> {{GetMethodName operation "Async"}}<T>(
|
public static async Task<T> {{GetMethodName api.operation "Async"}}<T>(
|
||||||
this I{{name}}Operations operations,
|
this I{{name}}Operations operations,
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetType .}} {{GetDotNetName . "true"}},
|
{{GetDotNetTypeOpenApiParameter parameter}} {{GetDotNetNameOpenApiParameter parameter "true"}},
|
||||||
{{/operation.parameters}}
|
{{ end }}
|
||||||
CancellationToken cancellationToken = default(CancellationToken))
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}<T>(
|
using (var _result = await operations.{{GetMethodName api.operation "WithHttpMessagesAsync"}}<T>(
|
||||||
{{#operation.parameters}}
|
{{ for parameter in api.operation.parameters}}
|
||||||
{{GetDotNetName .}},
|
{{GetDotNetNameOpenApiParameter parameter "false"}},
|
||||||
{{/operation.parameters}}
|
{{end}}
|
||||||
null,
|
null,
|
||||||
cancellationToken).ConfigureAwait(false))
|
cancellationToken).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
return _result.Body;
|
return _result.Body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/IfReturnType}}
|
{{end}}
|
||||||
|
|
||||||
{{/apis}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user