@@ -41,6 +41,15 @@ let _ = require('lodash'),
41
41
_ . forEach ( paths , function ( completePath ) {
42
42
let pathSplit = completePath === '/' ? [ completePath ] : _ . compact ( completePath . split ( '/' ) ) ;
43
43
44
+ /**
45
+ * /user
46
+ * /team
47
+ * /hi
48
+ * /bye
49
+ *
50
+ * In this scenario, always create a base folder for the path
51
+ * and then add and link the request inside the created folder.
52
+ */
44
53
if ( pathSplit . length === 1 ) {
45
54
let methods = openapi . paths [ completePath ] ;
46
55
@@ -57,6 +66,20 @@ let _ = require('lodash'),
57
66
return ;
58
67
}
59
68
69
+ if ( ! tree . hasNode ( `path:folder:${ pathSplit [ 0 ] } ` ) ) {
70
+ tree . setNode ( `path:folder:${ pathSplit [ 0 ] } ` , {
71
+ type : 'folder' ,
72
+ meta : {
73
+ name : pathSplit [ 0 ] ,
74
+ path : pathSplit [ 0 ] ,
75
+ pathIdentifier : pathSplit [ 0 ]
76
+ } ,
77
+ data : { }
78
+ } ) ;
79
+
80
+ tree . setEdge ( 'root:collection' , `path:folder:${ pathSplit [ 0 ] } ` ) ;
81
+ }
82
+
60
83
tree . setNode ( `path:request:${ pathSplit [ 0 ] } :${ method } ` , {
61
84
type : 'request' ,
62
85
data : { } ,
@@ -67,13 +90,7 @@ let _ = require('lodash'),
67
90
}
68
91
} ) ;
69
92
70
- if ( tree . hasNode ( `path:folder:${ pathSplit [ 0 ] } ` ) ) {
71
- tree . setEdge ( `path:folder:${ pathSplit [ 0 ] } ` , `path:request:${ pathSplit [ 0 ] } :${ method } ` ) ;
72
- }
73
-
74
- else {
75
- tree . setEdge ( 'root:collection' , `path:request:${ pathSplit [ 0 ] } :${ method } ` ) ;
76
- }
93
+ tree . setEdge ( `path:folder:${ pathSplit [ 0 ] } ` , `path:request:${ pathSplit [ 0 ] } :${ method } ` ) ;
77
94
} ) ;
78
95
}
79
96
@@ -98,6 +115,28 @@ let _ = require('lodash'),
98
115
return ;
99
116
}
100
117
118
+ /**
119
+ * If it is the last node,
120
+ * it might happen that this exists as a folder.
121
+ *
122
+ * If yes add a request inside that folder else
123
+ * add as a request on the previous path idendified which will be a folder.
124
+ */
125
+ if ( ! tree . hasNode ( `path:folder:${ pathIdentifier } ` ) ) {
126
+ tree . setNode ( `path:folder:${ pathIdentifier } ` , {
127
+ type : 'folder' ,
128
+ meta : {
129
+ name : path ,
130
+ path : path ,
131
+ pathIdentifier : pathIdentifier
132
+ } ,
133
+ data : { }
134
+ } ) ;
135
+
136
+ tree . setEdge ( index === 0 ? 'root:collection' : `path:folder:${ previousPathIdentified } ` ,
137
+ `path:folder:${ pathIdentifier } ` ) ;
138
+ }
139
+
101
140
tree . setNode ( `path:request:${ pathIdentifier } :${ method } ` , {
102
141
type : 'request' ,
103
142
data : { } ,
@@ -108,20 +147,7 @@ let _ = require('lodash'),
108
147
}
109
148
} ) ;
110
149
111
- /**
112
- * If it is the last node,
113
- * it might happen that this exists as a folder.
114
- *
115
- * If yes add a request inside that folder else
116
- * add as a request on the previous path idendified which will be a folder.
117
- */
118
- if ( tree . hasNode ( `path:folder:${ pathIdentifier } ` ) ) {
119
- tree . setEdge ( `path:folder:${ pathIdentifier } ` , `path:request:${ pathIdentifier } :${ method } ` ) ;
120
- }
121
-
122
- else {
123
- tree . setEdge ( `path:folder:${ previousPathIdentified } ` , `path:request:${ pathIdentifier } :${ method } ` ) ;
124
- }
150
+ tree . setEdge ( `path:folder:${ pathIdentifier } ` , `path:request:${ pathIdentifier } :${ method } ` ) ;
125
151
} ) ;
126
152
}
127
153
0 commit comments