11using System . Collections . Generic ;
2+ using System . Globalization ;
23using System . Linq ;
34using Simplify . Web . Meta ;
45using Simplify . Web . Postman . Models ;
@@ -33,7 +34,7 @@ private static void BuildCollectionItems(CollectionItem currentLevelContainer, i
3334 var path = item . Request . Url . Path ;
3435
3536 // If recursion reached request level or reached route parameter
36- if ( currentLevel == path . Count - 1 || path [ currentLevel ] . StartsWith ( "{" ) )
37+ if ( currentLevel == path . Count || path [ currentLevel ] . StartsWith ( "{" ) )
3738 {
3839 if ( currentLevelContainer . Items == null )
3940 currentLevelContainer . Items = new List < CollectionItem > ( ) ;
@@ -44,27 +45,33 @@ private static void BuildCollectionItems(CollectionItem currentLevelContainer, i
4445
4546 // If path recursion not reached request level
4647
47- var containerName = path [ currentLevel ] ;
48+ var containerName = BuildContainerName ( path [ currentLevel ] ) ;
4849
49- var container = currentLevelContainer . Items . FirstOrDefault ( x => x . Name == containerName ) ;
50+ var container = currentLevelContainer . Items ? . FirstOrDefault ( x => x . Name == containerName ) ;
5051
5152 if ( container == null )
53+ {
54+ if ( currentLevelContainer . Items == null )
55+ currentLevelContainer . Items = new List < CollectionItem > ( ) ;
56+
5257 currentLevelContainer . Items . Add ( container = new CollectionItem
5358 {
5459 Name = containerName ,
5560 Items = new List < CollectionItem > ( )
5661 } ) ;
62+ }
5763
5864 BuildCollectionItems ( container , currentLevel + 1 , item ) ;
5965 }
6066
6167 private static CollectionItem BuildRequestCollectionItem ( IControllerMetaData metaData , KeyValuePair < HttpMethod , string > route ) =>
6268 new ( )
6369 {
64- Name = BuildName ( metaData ) ,
70+ Name = BuildRequestName ( metaData ) ,
6571 Request = RequestBuilder . Build ( metaData , route )
6672 } ;
6773
68- private static string BuildName ( IControllerMetaData metaData ) => metaData . ControllerType . Name ;
74+ private static string BuildRequestName ( IControllerMetaData metaData ) => metaData . ControllerType . Name . Replace ( "Controller" , "" ) ;
75+ private static string BuildContainerName ( string urlPart ) => CultureInfo . CurrentCulture . TextInfo . ToTitleCase ( urlPart . ToLower ( ) ) ;
6976 }
7077}
0 commit comments