@@ -248,4 +248,83 @@ public static bool IsAsyncEnumerableEnabled(
248248 this OpenApiOperation operation )
249249 => operation . Extensions . TryGetValue ( "x-return-async-enumerable" , out var extension ) &&
250250 extension is OpenApiBoolean { Value : true } ;
251+
252+ //// ! This from Atc.OpenApi.OpenApiOperationExtensions - remove this when OpenApi in this project is updated!
253+ private const string RegexPatternUppercase = @"(?<!^)(?=[A-Z])" ;
254+
255+ //// ! This from Atc.OpenApi.OpenApiOperationExtensions - remove this when OpenApi in this project is updated!
256+ public static bool IsOperationNamePluralized2 (
257+ this OpenApiOperation openApiOperation ,
258+ OperationType operationType )
259+ {
260+ if ( openApiOperation is null )
261+ {
262+ throw new ArgumentNullException ( nameof ( openApiOperation ) ) ;
263+ }
264+
265+ var operationName = openApiOperation . GetOperationName ( ) ;
266+
267+ // Remove Http-verb
268+ if ( operationName . StartsWith ( operationType . ToString ( ) , StringComparison . Ordinal ) )
269+ {
270+ operationName = operationName [ operationType . ToString ( ) . Length ..] ;
271+ }
272+
273+ // Split by uppercase
274+ var sa = System . Text . RegularExpressions . Regex . Split ( operationName , RegexPatternUppercase , System . Text . RegularExpressions . RegexOptions . None , TimeSpan . FromSeconds ( 1 ) ) ;
275+ if ( sa . Length > 0 )
276+ {
277+ // Test for last-term
278+ var termWord = sa [ ^ 1 ] ;
279+ if ( termWord . EndsWith ( 's' ) &&
280+ ! ( termWord . Equals ( "Ids" , StringComparison . Ordinal ) ||
281+ termWord . Equals ( "Identifiers" , StringComparison . Ordinal ) ||
282+ termWord . Equals ( "Details" , StringComparison . Ordinal ) ||
283+ termWord . Equals ( "Status" , StringComparison . Ordinal ) ) )
284+ {
285+ return true ;
286+ }
287+
288+ // Test for first-term
289+ termWord = sa [ 0 ] ;
290+ if ( termWord . EndsWith ( 's' ) )
291+ {
292+ return true ;
293+ }
294+
295+ if ( sa . Any ( x => x . Equals ( "By" , StringComparison . Ordinal ) ) )
296+ {
297+ var index = Array . IndexOf ( sa , "By" ) ;
298+ if ( index > 1 )
299+ {
300+ termWord = sa [ index - 1 ] ;
301+ if ( termWord . Equals ( "Details" , StringComparison . Ordinal ) ||
302+ termWord . Equals ( "Status" , StringComparison . Ordinal ) )
303+ {
304+ return false ;
305+ }
306+
307+ if ( termWord . EndsWith ( 's' ) )
308+ {
309+ return true ;
310+ }
311+ }
312+ }
313+ }
314+
315+ return false ;
316+ }
317+
318+ //// ! This from Atc.OpenApi.OpenApiOperationExtensions - remove this when OpenApi in this project is updated!
319+ public static bool IsOperationIdPluralized2 (
320+ this OpenApiOperation openApiOperation ,
321+ OperationType operationType )
322+ {
323+ if ( openApiOperation is null )
324+ {
325+ throw new ArgumentNullException ( nameof ( openApiOperation ) ) ;
326+ }
327+
328+ return IsOperationNamePluralized2 ( openApiOperation , operationType ) ;
329+ }
251330}
0 commit comments