Skip to content

Commit 6650a28

Browse files
committed
PR feedback updates
1 parent 7d36d69 commit 6650a28

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ namespace Microsoft.OpenApi.Services
1313
/// </summary>
1414
public class OpenApiUrlTreeNode
1515
{
16+
private const string RootPathSegment = "/";
17+
private const string PathSeparator = "\\";
18+
1619
/// <summary>
1720
/// All the subdirectories of a node.
1821
/// </summary>
@@ -72,7 +75,7 @@ private OpenApiUrlTreeNode(string segment)
7275
/// <returns>The root node of the created <see cref="OpenApiUrlTreeNode"/> directory structure.</returns>
7376
public static OpenApiUrlTreeNode Create()
7477
{
75-
return new OpenApiUrlTreeNode("/");
78+
return new OpenApiUrlTreeNode(RootPathSegment);
7679
}
7780

7881
/// <summary>
@@ -86,7 +89,7 @@ public static OpenApiUrlTreeNode Create(OpenApiDocument doc, string label)
8689
Utils.CheckArgumentNull(doc, nameof(doc));
8790
Utils.CheckArgumentNullOrEmpty(label, nameof(label));
8891

89-
OpenApiUrlTreeNode root = new OpenApiUrlTreeNode("/");
92+
var root = Create();
9093

9194
var paths = doc.Paths;
9295
if (paths != null)
@@ -112,7 +115,7 @@ public void Attach(OpenApiDocument doc, string label)
112115
Utils.CheckArgumentNull(doc, nameof(doc));
113116
Utils.CheckArgumentNullOrEmpty(label, nameof(label));
114117

115-
var paths = doc?.Paths;
118+
var paths = doc.Paths;
116119
if (paths != null)
117120
{
118121
foreach (var path in paths)
@@ -137,7 +140,7 @@ public OpenApiUrlTreeNode Attach(string path,
137140
{
138141
Utils.CheckArgumentNullOrEmpty(label, nameof(label));
139142

140-
if (path.StartsWith("/"))
143+
if (path.StartsWith(RootPathSegment))
141144
{
142145
// Remove leading slash
143146
path = path.Substring(1);
@@ -180,24 +183,28 @@ private OpenApiUrlTreeNode Attach(IEnumerable<string> segments,
180183
// If the child segment has already been defined, then insert into it
181184
if (Children.ContainsKey(segment))
182185
{
186+
var newPath = currentPath + PathSeparator + segment;
187+
183188
return Children[segment].Attach(segments: segments.Skip(1),
184189
pathItem: pathItem,
185190
label: label,
186-
currentPath: currentPath + "\\" + segment);
191+
currentPath: newPath);
187192
}
188193
else
189194
{
195+
var newPath = currentPath + PathSeparator + segment;
196+
190197
var node = new OpenApiUrlTreeNode(segment)
191198
{
192-
Path = currentPath + "\\" + segment
199+
Path = newPath
193200
};
194201

195202
Children[segment] = node;
196203

197204
return node.Attach(segments: segments.Skip(1),
198205
pathItem: pathItem,
199206
label: label,
200-
currentPath: currentPath + "\\" + segment);
207+
currentPath: newPath);
201208
}
202209
}
203210

0 commit comments

Comments
 (0)