File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ) )
You can’t perform that action at this time.
0 commit comments