adopt newer source generator (#1417)
* build on net8 * fix fmt * remove net8 for build * fix fmt * fix file load * mv proj * fix path * address comment * address comments
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
|
||||
3D1864AA-1FFC-4512-BB13-46055E410F73
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
@@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "simple", "examples\simple\s
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "watch", "examples\watch\watch.csproj", "{1DDB0CCF-7CCE-4A60-BAC6-9AE1779DEDB5}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3D1864AA-1FFC-4512-BB13-46055E410F73}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KubernetesClient", "src\KubernetesClient\KubernetesClient.csproj", "{35DD7248-F9EC-4272-A32C-B0C59E5A6FA7}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}"
|
||||
@@ -39,8 +37,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "customResource", "examples\
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generic", "examples\generic\generic.csproj", "{F06D4C3A-7825-43A8-832B-6BDE3D355486}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibKubernetesGenerator", "src\LibKubernetesGenerator\LibKubernetesGenerator.csproj", "{64C71596-B916-46EF-8115-B53E238F79D4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "portforward", "examples\portforward\portforward.csproj", "{DFBB1025-BD22-459D-A04D-E2AB31E129E2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "prometheus", "examples\prometheus\prometheus.csproj", "{682B94E4-1761-48FF-B5D0-87B45DC0C735}"
|
||||
@@ -451,7 +447,6 @@ Global
|
||||
{1AA79D75-E7C4-4C0C-928B-FB12EC3CBF68} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{DDB14203-DD5B-452A-A1E0-9FD98629101F} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{1DDB0CCF-7CCE-4A60-BAC6-9AE1779DEDB5} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{35DD7248-F9EC-4272-A32C-B0C59E5A6FA7} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
|
||||
{806AD0E5-833F-42FB-A870-4BCEE7F4B17F} = {8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}
|
||||
{04DE2C84-117D-4E21-8B45-B7AE627697BD} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{B9647AD4-F6B0-406F-8B79-6781E31600EC} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
@@ -459,21 +454,17 @@ Global
|
||||
{4D2AE427-F856-49E5-B61D-EA6B17D89051} = {8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}
|
||||
{95672061-5799-4454-ACDB-D6D330DB1EC4} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{F06D4C3A-7825-43A8-832B-6BDE3D355486} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{64C71596-B916-46EF-8115-B53E238F79D4} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
|
||||
{DFBB1025-BD22-459D-A04D-E2AB31E129E2} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{682B94E4-1761-48FF-B5D0-87B45DC0C735} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{17AB0AD8-6C90-42DD-880C-16B5AC4A373F} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{80F19E8A-F097-4AA4-A68C-D417B96BBC68} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
|
||||
{FD90C861-56C6-4536-B7F5-AC7779296384} = {8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}
|
||||
{F626860C-F141-45B3-9DDD-88AD3932ACAF} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{973CCB4A-F344-4C4F-81A5-0F40F7F43C07} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{21201F30-5463-4FC6-93C3-FBF157F0D46C} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
|
||||
{9128F6DC-6B7A-417F-937A-90461D6989A8} = {8AF4A5C2-F0CE-47D5-A4C5-FE4AB83CA509}
|
||||
{8E266190-AE6E-44A8-948D-BD974AA82428} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{C0759F88-A010-4DEF-BD3B-E183D3328FFC} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{05DC8884-AC54-4603-AC25-AE9D9F24E7AE} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{CC41E248-2139-427E-8DD4-B047A8924FD2} = {B70AFB57-57C9-46DC-84BE-11B7DDD34B40}
|
||||
{F1C8276A-8A60-4362-96B8-A006314446AE} = {3D1864AA-1FFC-4512-BB13-46055E410F73}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {049A763A-C891-4E8D-80CF-89DD3E22ADC7}
|
||||
|
||||
@@ -123,10 +123,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
|
||||
<AdditionalFiles Include="..\..\swagger.json"
|
||||
Generator="model,modelext,api,version,versionconverterstub" />
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj"
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\generators\LibKubernetesGenerator\LibKubernetesGenerator.csproj"
|
||||
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -5,9 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
|
||||
<AdditionalFiles Include="..\..\swagger.json" Generator="versionconverterautomap,version" />
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\generators\LibKubernetesGenerator.Automapper\LibKubernetesGenerator.Automapper.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<RootNamespace>k8s</RootNamespace>
|
||||
<!-- seems bug in net7 json generator, some types missing in its result
|
||||
net8 is still in preview, will enable it after net8 release -->
|
||||
<!-- <PublishAot Condition="'$(TargetFramework)' == 'net8.0'">true</PublishAot> -->
|
||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -75,10 +79,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Generator" />
|
||||
<AdditionalFiles Include="..\..\swagger.json"
|
||||
Generator="model,modelext,api,version,versionconverterstub" />
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\LibKubernetesGenerator.csproj"
|
||||
<ProjectReference Include="..\LibKubernetesGenerator\generators\LibKubernetesGenerator\LibKubernetesGenerator.csproj"
|
||||
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace LibKubernetesGenerator
|
||||
{
|
||||
internal class ApiGenerator
|
||||
{
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||
{
|
||||
var data = swagger.Operations
|
||||
.Where(o => o.Method != OpenApiOperationMethod.Options)
|
||||
|
||||
18
src/LibKubernetesGenerator/EmbedResource.cs
Normal file
18
src/LibKubernetesGenerator/EmbedResource.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace LibKubernetesGenerator;
|
||||
|
||||
internal static class EmbedResource
|
||||
{
|
||||
public static string GetResource(string name)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
var resourceName = assembly.GetName().Name + "." + name;
|
||||
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
using var reader = new StreamReader(stream ?? throw new FileNotFoundException(resourceName));
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Nustache.Core;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LibKubernetesGenerator
|
||||
{
|
||||
internal static class GeneratorExecutionContextExt
|
||||
{
|
||||
public static void RenderToContext(this GeneratorExecutionContext context, string templatefile, object data, string generatedfile)
|
||||
public static void RenderToContext(this IncrementalGeneratorPostInitializationContext context, string templatefile, object data, string generatedfile)
|
||||
{
|
||||
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.projectdir", out var root);
|
||||
var generated = Render.FileToString(Path.Combine(root, "..", "LibKubernetesGenerator", "templates", templatefile), data);
|
||||
var template = EmbedResource.GetResource(templatefile);
|
||||
var generated = Render.StringToString(template, data);
|
||||
context.AddSource(generatedfile, SourceText.From(generated, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,28 +2,42 @@ using Autofac;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using NSwag;
|
||||
using Nustache.Core;
|
||||
#if GENERATE_AUTOMAPPER
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace LibKubernetesGenerator
|
||||
{
|
||||
[Generator]
|
||||
public class KubernetesClientSourceGenerator : ISourceGenerator
|
||||
public class KubernetesClientSourceGenerator : IIncrementalGenerator
|
||||
{
|
||||
private static readonly object Execlock = new object();
|
||||
|
||||
public void ExecuteInner(GeneratorExecutionContext context)
|
||||
private static (OpenApiDocument, IContainer) BuildContainer()
|
||||
{
|
||||
lock (Execlock)
|
||||
var swagger = OpenApiDocument.FromJsonAsync(EmbedResource.GetResource("swagger.json")).GetAwaiter().GetResult();
|
||||
var container = BuildContainer(swagger);
|
||||
// TODO move to Handlebars.Net
|
||||
// here is to clean up the custom helpers in static Nustache.Core.Helpers
|
||||
{
|
||||
var swaggerfile = context.AdditionalFiles.First(f => f.Path.EndsWith("swagger.json"));
|
||||
var swagger = OpenApiDocument.FromJsonAsync(swaggerfile.GetText().ToString()).GetAwaiter().GetResult();
|
||||
var ch = typeof(Helpers).GetField("CustomHelpers", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
((Dictionary<string, Helper>)ch.GetValue(null)).Clear();
|
||||
}
|
||||
|
||||
context.AnalyzerConfigOptions.GetOptions(swaggerfile).TryGetValue("build_metadata.AdditionalFiles.Generator", out var generatorSetting);
|
||||
var generators = new HashSet<string>(generatorSetting.Split(','));
|
||||
foreach (var helper in container.Resolve<IEnumerable<INustacheHelper>>())
|
||||
{
|
||||
helper.RegisterHelper();
|
||||
}
|
||||
|
||||
return (swagger, container);
|
||||
}
|
||||
|
||||
private static IContainer BuildContainer(OpenApiDocument swagger)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterType<ClassNameHelper>()
|
||||
@@ -70,78 +84,60 @@ namespace LibKubernetesGenerator
|
||||
builder.RegisterType<VersionConverterAutoMapperGenerator>();
|
||||
builder.RegisterType<VersionGenerator>();
|
||||
|
||||
var container = builder.Build();
|
||||
// TODO move to Handlebars.Net
|
||||
{
|
||||
var ch = typeof(Helpers).GetField("CustomHelpers", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
((Dictionary<string, Helper>)ch.GetValue(null)).Clear();
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
foreach (var helper in container.Resolve<IEnumerable<INustacheHelper>>())
|
||||
public void Initialize(IncrementalGeneratorInitializationContext generatorContext)
|
||||
{
|
||||
helper.RegisterHelper();
|
||||
}
|
||||
#if GENERATE_BASIC
|
||||
generatorContext.RegisterPostInitializationOutput(ctx =>
|
||||
{
|
||||
lock (Execlock)
|
||||
{
|
||||
var (swagger, container) = BuildContainer();
|
||||
|
||||
container.Resolve<VersionGenerator>().Generate(swagger, ctx);
|
||||
|
||||
if (generators.Contains("api"))
|
||||
{
|
||||
container.Resolve<ApiGenerator>().Generate(swagger, context);
|
||||
}
|
||||
container.Resolve<ModelGenerator>().Generate(swagger, ctx);
|
||||
container.Resolve<ModelExtGenerator>().Generate(swagger, ctx);
|
||||
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, ctx);
|
||||
|
||||
if (generators.Contains("model"))
|
||||
{
|
||||
container.Resolve<ModelGenerator>().Generate(swagger, context);
|
||||
container.Resolve<ApiGenerator>().Generate(swagger, ctx);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
if (generators.Contains("modelext"))
|
||||
#if GENERATE_AUTOMAPPER
|
||||
var automappersrc = generatorContext.CompilationProvider.Select((c, _) => c.SyntaxTrees.First(s => PathSuffixMath(s.FilePath, "AutoMapper/VersionConverter.cs")));
|
||||
generatorContext.RegisterSourceOutput(automappersrc, (ctx, srctree) =>
|
||||
{
|
||||
container.Resolve<ModelExtGenerator>().Generate(swagger, context);
|
||||
}
|
||||
lock (Execlock)
|
||||
{
|
||||
var (swagger, container) = BuildContainer();
|
||||
|
||||
if (generators.Contains("versionconverterstub"))
|
||||
{
|
||||
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, context);
|
||||
container.Resolve<VersionConverterAutoMapperGenerator>().Generate(swagger, ctx, srctree);
|
||||
}
|
||||
|
||||
if (generators.Contains("versionconverterautomap"))
|
||||
{
|
||||
container.Resolve<VersionConverterAutoMapperGenerator>().Generate(swagger, context);
|
||||
}
|
||||
|
||||
if (generators.Contains("version"))
|
||||
{
|
||||
container.Resolve<VersionGenerator>().Generate(swagger, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
ExecuteInner(context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
new DiagnosticDescriptor(
|
||||
"K8SCSG01",
|
||||
e.Message,
|
||||
e.StackTrace,
|
||||
"Kubernetes C# code generator",
|
||||
DiagnosticSeverity.Error,
|
||||
true), Location.None));
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
#if DEBUG
|
||||
// if (!Debugger.IsAttached)
|
||||
// {
|
||||
// Debugger.Launch();
|
||||
// }
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
#if GENERATE_AUTOMAPPER
|
||||
private IEnumerable<string> PathSplit(string path)
|
||||
{
|
||||
var p = path;
|
||||
|
||||
while (!string.IsNullOrEmpty(p))
|
||||
{
|
||||
yield return Path.GetFileName(p);
|
||||
p = Path.GetDirectoryName(p);
|
||||
}
|
||||
}
|
||||
|
||||
private bool PathSuffixMath(string path, string suffix)
|
||||
{
|
||||
var s = PathSplit(suffix).ToList();
|
||||
return PathSplit(path).Take(s.Count).SequenceEqual(s);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<NoWarn>CA1812</NoWarn>
|
||||
@@ -6,8 +6,13 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)/*.cs" />
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)/../../swagger.json" WithCulture="false" Visible="false" />
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)/templates/*" WithCulture="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -14,7 +14,7 @@ namespace LibKubernetesGenerator
|
||||
this.classNameHelper = classNameHelper;
|
||||
}
|
||||
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||
{
|
||||
// Generate the interface declarations
|
||||
var skippedTypes = new HashSet<string> { "V1WatchEvent" };
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace LibKubernetesGenerator
|
||||
this.classNameHelper = classNameHelper;
|
||||
}
|
||||
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||
{
|
||||
foreach (var kv in swagger.Definitions)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using NSwag;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -19,7 +17,7 @@ namespace LibKubernetesGenerator
|
||||
this.classNameHelper = classNameHelper;
|
||||
}
|
||||
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, SourceProductionContext context, SyntaxTree manualconverter)
|
||||
{
|
||||
var allGeneratedModelClassNames = new List<string>();
|
||||
|
||||
@@ -32,7 +30,6 @@ namespace LibKubernetesGenerator
|
||||
|
||||
var manualMaps = new List<(string, string)>();
|
||||
|
||||
var manualconverter = context.Compilation.SyntaxTrees.First(s => PathSuffixMath(s.FilePath, "AutoMapper/VersionConverter.cs"));
|
||||
manualMaps = Regex.Matches(manualconverter.GetText().ToString(), @"\.CreateMap<(?<T1>.+?),\s?(?<T2>.+?)>")
|
||||
.OfType<Match>()
|
||||
.Select(x => (x.Groups["T1"].Value, x.Groups["T2"].Value))
|
||||
@@ -81,22 +78,5 @@ internal static partial class VersionConverter
|
||||
|
||||
context.AddSource($"VersionConverter.g.cs", SourceText.From(sbversion.ToString(), Encoding.UTF8));
|
||||
}
|
||||
|
||||
private IEnumerable<string> PathSplit(string path)
|
||||
{
|
||||
var p = path;
|
||||
|
||||
while (!string.IsNullOrEmpty(p))
|
||||
{
|
||||
yield return Path.GetFileName(p);
|
||||
p = Path.GetDirectoryName(p);
|
||||
}
|
||||
}
|
||||
|
||||
private bool PathSuffixMath(string path, string suffix)
|
||||
{
|
||||
var s = PathSplit(suffix).ToList();
|
||||
return PathSplit(path).Take(s.Count).SequenceEqual(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace LibKubernetesGenerator
|
||||
this.classNameHelper = classNameHelper;
|
||||
}
|
||||
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||
{
|
||||
var allGeneratedModelClassNames = new List<string>();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace LibKubernetesGenerator;
|
||||
|
||||
internal class VersionGenerator
|
||||
{
|
||||
public void Generate(OpenApiDocument swagger, GeneratorExecutionContext context)
|
||||
public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context)
|
||||
{
|
||||
context.AddSource("k8sver.cs", $"// <auto-generated />\n" + "internal static partial class ThisAssembly { internal const string KubernetesSwaggerVersion = \"" + swagger.Info.Version + "\";}");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants);GENERATE_AUTOMAPPER;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="../../LibKubernetesGenerator.target" />
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants);GENERATE_BASIC;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="../../LibKubernetesGenerator.target" />
|
||||
|
||||
</Project>
|
||||
@@ -16,3 +16,15 @@ namespace k8s.Models
|
||||
|
||||
{{/.}}
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
namespace k8s
|
||||
{
|
||||
{{#.}}
|
||||
[JsonSerializable(typeof({{GetClassName . }}))]
|
||||
{{/.}}
|
||||
internal partial class SourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user