Skip to content

Commit 6de5558

Browse files
committed
refactor: enhance type resolution for list items in TypeHelper by adding TryGetItemTypeFromSchema method
1 parent 5e47c09 commit 6de5558

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/LibKubernetesGenerator/TypeHelper.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,14 @@ string toType()
246246

247247
break;
248248
case "T":
249-
// Return single item type from list type (e.g., V1Pod from V1PodList)
250-
return !string.IsNullOrEmpty(t) && t.EndsWith("List", StringComparison.Ordinal)
251-
? t.Substring(0, t.Length - 4)
252-
: t;
249+
var itemType = TryGetItemTypeFromSchema(response);
250+
if (itemType != null)
251+
{
252+
return itemType;
253+
}
254+
255+
break;
253256
case "TList":
254-
// Return list type as-is
255257
return t;
256258
}
257259

@@ -291,5 +293,26 @@ public static bool IfType(JsonSchemaProperty property, string type)
291293

292294
return false;
293295
}
296+
297+
private string TryGetItemTypeFromSchema(OpenApiResponse response)
298+
{
299+
var listSchema = response?.Schema?.Reference;
300+
if (listSchema?.Properties?.TryGetValue("items", out var itemsProperty) != true)
301+
{
302+
return null;
303+
}
304+
305+
if (itemsProperty.Reference != null)
306+
{
307+
return classNameHelper.GetClassNameForSchemaDefinition(itemsProperty.Reference);
308+
}
309+
310+
if (itemsProperty.Item?.Reference != null)
311+
{
312+
return classNameHelper.GetClassNameForSchemaDefinition(itemsProperty.Item.Reference);
313+
}
314+
315+
return null;
316+
}
294317
}
295318
}

0 commit comments

Comments
 (0)