1
1
using System . Collections . Generic ;
2
+ using System . Globalization ;
2
3
using System . Linq ;
3
4
using Simplify . Web . Meta ;
4
5
using Simplify . Web . Postman . Models ;
@@ -33,7 +34,7 @@ private static void BuildCollectionItems(CollectionItem currentLevelContainer, i
33
34
var path = item . Request . Url . Path ;
34
35
35
36
// 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 ( "{" ) )
37
38
{
38
39
if ( currentLevelContainer . Items == null )
39
40
currentLevelContainer . Items = new List < CollectionItem > ( ) ;
@@ -44,27 +45,33 @@ private static void BuildCollectionItems(CollectionItem currentLevelContainer, i
44
45
45
46
// If path recursion not reached request level
46
47
47
- var containerName = path [ currentLevel ] ;
48
+ var containerName = BuildContainerName ( path [ currentLevel ] ) ;
48
49
49
- var container = currentLevelContainer . Items . FirstOrDefault ( x => x . Name == containerName ) ;
50
+ var container = currentLevelContainer . Items ? . FirstOrDefault ( x => x . Name == containerName ) ;
50
51
51
52
if ( container == null )
53
+ {
54
+ if ( currentLevelContainer . Items == null )
55
+ currentLevelContainer . Items = new List < CollectionItem > ( ) ;
56
+
52
57
currentLevelContainer . Items . Add ( container = new CollectionItem
53
58
{
54
59
Name = containerName ,
55
60
Items = new List < CollectionItem > ( )
56
61
} ) ;
62
+ }
57
63
58
64
BuildCollectionItems ( container , currentLevel + 1 , item ) ;
59
65
}
60
66
61
67
private static CollectionItem BuildRequestCollectionItem ( IControllerMetaData metaData , KeyValuePair < HttpMethod , string > route ) =>
62
68
new ( )
63
69
{
64
- Name = BuildName ( metaData ) ,
70
+ Name = BuildRequestName ( metaData ) ,
65
71
Request = RequestBuilder . Build ( metaData , route )
66
72
} ;
67
73
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 ( ) ) ;
69
76
}
70
77
}
0 commit comments