Skip to content
Open
Changes from 1 commit
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
33 changes: 28 additions & 5 deletions src/LibKubernetesGenerator/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@

break;
case "T":
// Return single item type from list type (e.g., V1Pod from V1PodList)
return !string.IsNullOrEmpty(t) && t.EndsWith("List", StringComparison.Ordinal)
? t.Substring(0, t.Length - 4)
: t;
var itemType = TryGetItemTypeFromSchema(response);
if (itemType != null)
{
return itemType;
}

break;
case "TList":
// Return list type as-is
return t;
}

Expand Down Expand Up @@ -291,5 +293,26 @@

return false;
}

private string TryGetItemTypeFromSchema(OpenApiResponse response)
{
var listSchema = response?.Schema?.Reference;
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true)
Comment on lines +298 to +299
Copy link
Preview

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code attempts to access Properties on Reference which is incorrect. The Reference property is a string reference to a schema definition, not the actual schema object. This should be accessing the resolved schema object instead of the reference.

Suggested change
var listSchema = response?.Schema?.Reference;
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true)
// Resolve the schema reference to the actual schema object
var referencedSchema = response?.Schema?.ActualSchema;
if (referencedSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true)

Copilot uses AI. Check for mistakes.

{
return null;
}
Comment on lines +298 to +302
Copy link
Preview

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method attempts to access Properties on a JsonReference object, but JsonReference doesn't have a Properties property. This will always return null. You should resolve the reference first to get the actual schema.

Suggested change
var listSchema = response?.Schema?.Reference;
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true)
{
return null;
}
// Resolve the reference to the actual schema before accessing Properties
var referencedSchema = response?.Schema?.Reference as JsonSchema;
if (referencedSchema == null)
{
return null;
}
if (!referencedSchema.Properties.TryGetValue("items", out var itemsProperty))
{
return null;
}

Copilot uses AI. Check for mistakes.


if (itemsProperty.Reference != null)
{
return classNameHelper.GetClassNameForSchemaDefinition(itemsProperty.Reference);
}

Check warning on line 309 in src/LibKubernetesGenerator/TypeHelper.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Check warning on line 309 in src/LibKubernetesGenerator/TypeHelper.cs

View workflow job for this annotation

GitHub Actions / Dotnet build (macOS-latest)

if (itemsProperty.Item?.Reference != null)
{
return classNameHelper.GetClassNameForSchemaDefinition(itemsProperty.Item.Reference);
}

return null;
}
}
}
Loading