@@ -13,6 +13,9 @@ namespace Microsoft.OpenApi.Services
13
13
/// </summary>
14
14
public class OpenApiUrlTreeNode
15
15
{
16
+ private const string RootPathSegment = "/" ;
17
+ private const string PathSeparator = "\\ " ;
18
+
16
19
/// <summary>
17
20
/// All the subdirectories of a node.
18
21
/// </summary>
@@ -72,7 +75,7 @@ private OpenApiUrlTreeNode(string segment)
72
75
/// <returns>The root node of the created <see cref="OpenApiUrlTreeNode"/> directory structure.</returns>
73
76
public static OpenApiUrlTreeNode Create ( )
74
77
{
75
- return new OpenApiUrlTreeNode ( "/" ) ;
78
+ return new OpenApiUrlTreeNode ( RootPathSegment ) ;
76
79
}
77
80
78
81
/// <summary>
@@ -86,7 +89,7 @@ public static OpenApiUrlTreeNode Create(OpenApiDocument doc, string label)
86
89
Utils . CheckArgumentNull ( doc , nameof ( doc ) ) ;
87
90
Utils . CheckArgumentNullOrEmpty ( label , nameof ( label ) ) ;
88
91
89
- OpenApiUrlTreeNode root = new OpenApiUrlTreeNode ( "/" ) ;
92
+ var root = Create ( ) ;
90
93
91
94
var paths = doc . Paths ;
92
95
if ( paths != null )
@@ -112,7 +115,7 @@ public void Attach(OpenApiDocument doc, string label)
112
115
Utils . CheckArgumentNull ( doc , nameof ( doc ) ) ;
113
116
Utils . CheckArgumentNullOrEmpty ( label , nameof ( label ) ) ;
114
117
115
- var paths = doc ? . Paths ;
118
+ var paths = doc . Paths ;
116
119
if ( paths != null )
117
120
{
118
121
foreach ( var path in paths )
@@ -137,7 +140,7 @@ public OpenApiUrlTreeNode Attach(string path,
137
140
{
138
141
Utils . CheckArgumentNullOrEmpty ( label , nameof ( label ) ) ;
139
142
140
- if ( path . StartsWith ( "/" ) )
143
+ if ( path . StartsWith ( RootPathSegment ) )
141
144
{
142
145
// Remove leading slash
143
146
path = path . Substring ( 1 ) ;
@@ -180,24 +183,28 @@ private OpenApiUrlTreeNode Attach(IEnumerable<string> segments,
180
183
// If the child segment has already been defined, then insert into it
181
184
if ( Children . ContainsKey ( segment ) )
182
185
{
186
+ var newPath = currentPath + PathSeparator + segment ;
187
+
183
188
return Children [ segment ] . Attach ( segments : segments . Skip ( 1 ) ,
184
189
pathItem : pathItem ,
185
190
label : label ,
186
- currentPath : currentPath + " \\ " + segment ) ;
191
+ currentPath : newPath ) ;
187
192
}
188
193
else
189
194
{
195
+ var newPath = currentPath + PathSeparator + segment ;
196
+
190
197
var node = new OpenApiUrlTreeNode ( segment )
191
198
{
192
- Path = currentPath + " \\ " + segment
199
+ Path = newPath
193
200
} ;
194
201
195
202
Children [ segment ] = node ;
196
203
197
204
return node . Attach ( segments : segments . Skip ( 1 ) ,
198
205
pathItem : pathItem ,
199
206
label : label ,
200
- currentPath : currentPath + " \\ " + segment ) ;
207
+ currentPath : newPath ) ;
201
208
}
202
209
}
203
210
0 commit comments