diff --git a/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs b/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs index 6ea216f28..7adf6ef1d 100644 --- a/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs +++ b/src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs @@ -59,6 +59,7 @@ private static IContainer BuildContainer(OpenApiDocument swagger) ; builder.RegisterType(); + builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); @@ -79,6 +80,7 @@ public void Initialize(IncrementalGeneratorInitializationContext generatorContex container.Resolve().Generate(swagger, ctx); container.Resolve().Generate(swagger, ctx); + container.Resolve().Generate(swagger, ctx); container.Resolve().Generate(swagger, ctx); container.Resolve().Generate(swagger, ctx); container.Resolve().Generate(swagger, ctx); diff --git a/src/LibKubernetesGenerator/SourceGenerationContextGenerator.cs b/src/LibKubernetesGenerator/SourceGenerationContextGenerator.cs new file mode 100644 index 000000000..c73c020a1 --- /dev/null +++ b/src/LibKubernetesGenerator/SourceGenerationContextGenerator.cs @@ -0,0 +1,24 @@ +using Microsoft.CodeAnalysis; +using NSwag; + +namespace LibKubernetesGenerator +{ + internal class SourceGenerationContextGenerator + { + private readonly ScriptObjectFactory scriptObjectFactory; + + public SourceGenerationContextGenerator(ScriptObjectFactory scriptObjectFactory) + { + this.scriptObjectFactory = scriptObjectFactory; + } + + public void Generate(OpenApiDocument swagger, IncrementalGeneratorPostInitializationContext context) + { + var definitions = swagger.Definitions.Values; + var sc = scriptObjectFactory.CreateScriptObject(); + sc.SetValue("definitions", definitions, true); + + context.RenderToContext("SourceGenerationContext.cs.template", sc, "SourceGenerationContext.g.cs"); + } + } +} diff --git a/src/LibKubernetesGenerator/templates/ModelExtensions.cs.template b/src/LibKubernetesGenerator/templates/ModelExtensions.cs.template index bad5507bc..d52a3e714 100644 --- a/src/LibKubernetesGenerator/templates/ModelExtensions.cs.template +++ b/src/LibKubernetesGenerator/templates/ModelExtensions.cs.template @@ -15,15 +15,3 @@ namespace k8s.Models } {{ end }} } - -#if NET8_0_OR_GREATER -namespace k8s -{ - {{ for definition in definitions }} - [JsonSerializable(typeof({{ GetClassName definition }}))] - {{ end }} - internal partial class SourceGenerationContext : JsonSerializerContext - { - } -} -#endif \ No newline at end of file diff --git a/src/LibKubernetesGenerator/templates/SourceGenerationContext.cs.template b/src/LibKubernetesGenerator/templates/SourceGenerationContext.cs.template new file mode 100644 index 000000000..82942f915 --- /dev/null +++ b/src/LibKubernetesGenerator/templates/SourceGenerationContext.cs.template @@ -0,0 +1,15 @@ +// +// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// +#if NET8_0_OR_GREATER +namespace k8s +{ + {{ for definition in definitions }} + [JsonSerializable(typeof({{ GetClassName definition }}))] + {{ end }} + internal partial class SourceGenerationContext : JsonSerializerContext + { + } +} +#endif \ No newline at end of file diff --git a/tests/E2E.Aot.Tests/MinikubeTests.cs b/tests/E2E.Aot.Tests/MinikubeTests.cs index 2c4ca933b..505d9a4b2 100644 --- a/tests/E2E.Aot.Tests/MinikubeTests.cs +++ b/tests/E2E.Aot.Tests/MinikubeTests.cs @@ -370,6 +370,15 @@ async Task AssertMd5sumAsync(string file, byte[] orig) } } + + [MinikubeFact] + public async Task VersionTestAsync() + { + using var client = CreateClient(); + var version = await client.Version.GetCodeAsync().ConfigureAwait(false); + Assert.NotNull(version); + } + public static IKubernetes CreateClient() { return new Kubernetes(KubernetesClientConfiguration.BuildDefaultConfig());