Skip to content

fix missing aot model SourceGenerationContext #1636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/LibKubernetesGenerator/KubernetesClientSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static IContainer BuildContainer(OpenApiDocument swagger)
;

builder.RegisterType<ModelExtGenerator>();
builder.RegisterType<SourceGenerationContextGenerator>();
builder.RegisterType<ModelGenerator>();
builder.RegisterType<ApiGenerator>();
builder.RegisterType<ClientSetGenerator>();
Expand All @@ -79,6 +80,7 @@ public void Initialize(IncrementalGeneratorInitializationContext generatorContex

container.Resolve<ModelGenerator>().Generate(swagger, ctx);
container.Resolve<ModelExtGenerator>().Generate(swagger, ctx);
container.Resolve<SourceGenerationContextGenerator>().Generate(swagger, ctx);
container.Resolve<VersionConverterStubGenerator>().Generate(swagger, ctx);
container.Resolve<ApiGenerator>().Generate(swagger, ctx);
container.Resolve<ClientSetGenerator>().Generate(swagger, ctx);
Expand Down
24 changes: 24 additions & 0 deletions src/LibKubernetesGenerator/SourceGenerationContextGenerator.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
12 changes: 0 additions & 12 deletions src/LibKubernetesGenerator/templates/ModelExtensions.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <auto-generated>
// 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.
// </auto-generated>
#if NET8_0_OR_GREATER
namespace k8s
{
{{ for definition in definitions }}
[JsonSerializable(typeof({{ GetClassName definition }}))]
{{ end }}
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
}
#endif
9 changes: 9 additions & 0 deletions tests/E2E.Aot.Tests/MinikubeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@
}
}


Check warning on line 373 in tests/E2E.Aot.Tests/MinikubeTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 373 in tests/E2E.Aot.Tests/MinikubeTests.cs

View workflow job for this annotation

GitHub Actions / e2e

[MinikubeFact]
public async Task VersionTestAsync()
{
using var client = CreateClient();
var version = await client.Version.GetCodeAsync().ConfigureAwait(false);
Assert.NotNull(version);
}

Check warning on line 380 in tests/E2E.Aot.Tests/MinikubeTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 380 in tests/E2E.Aot.Tests/MinikubeTests.cs

View workflow job for this annotation

GitHub Actions / e2e


public static IKubernetes CreateClient()
{
return new Kubernetes(KubernetesClientConfiguration.BuildDefaultConfig());
Expand Down
Loading