Skip to content

Commit f4462a4

Browse files
committed
feat: Add AreKeysUnique extension method and validate unique CLI action names
1 parent e8c9a46 commit f4462a4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/libs/AutoSDK/Extensions/StringExtensions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,26 @@ public static string LastWord(this string? text)
361361

362362
return text.Substring(start);
363363
}
364+
365+
/// <summary>
366+
/// Returns true when every element’s SomeKey value appears exactly once.
367+
/// </summary>
368+
/// <param name="items"></param>
369+
/// <param name="keySelector"></param>
370+
/// <typeparam name="T"></typeparam>
371+
/// <returns></returns>
372+
public static bool AreKeysUnique<T>(this IEnumerable<T> items, Func<T, object> keySelector)
373+
{
374+
items = items ?? throw new ArgumentNullException(nameof(items));
375+
keySelector = keySelector ?? throw new ArgumentNullException(nameof(keySelector));
376+
377+
// HashSet gives O(n) uniqueness check without extra allocations
378+
var seen = new HashSet<object>();
379+
380+
foreach (var item in items)
381+
if (!seen.Add(keySelector(item))) // Add() returns false if key already present
382+
return false; // duplicate found → stop early
383+
384+
return true; // no duplicates
385+
}
364386
}

src/libs/AutoSDK/Sources/Data.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ public static Models.Data Prepare(
195195
var methods = filteredOperations
196196
.Select(EndPoint.FromSchema)
197197
.ToImmutableArray();
198+
199+
foreach (var group in methods
200+
.GroupBy(x => x.Tag)
201+
.Where(x => !x.AreKeysUnique(y => y.CliAction)))
202+
{
203+
Console.WriteLine($"Found duplicate CLI action names in '{group.Key.SingularizedName}': {string.Join(", ", group.Select(x => x.CliAction))}");
204+
}
205+
198206
var authorizations = openApiDocument.SecurityRequirements!
199207
.SelectMany(requirement => requirement)
200208
.Select(x => Authorization.FromOpenApiSecurityScheme(x.Key, settings, globalSettings))

0 commit comments

Comments
 (0)