Skip to content

Commit 41c53c9

Browse files
Address feedback
- Create helpers to reduce code duplication. - Remove unused method.
1 parent fc91ab0 commit 41c53c9

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/Microsoft.OpenApi/Services/OpenApiWalker.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal void Walk(ISet<OpenApiTag>? tags)
9797
// Visit tags
9898
if (tags is HashSet<OpenApiTag> { Count: 1 } hashSet && hashSet.First() is { } only)
9999
{
100-
WalkItem("0", only, static (self, item) => self.Walk(item));
100+
WalkItem("0", only, Walk);
101101
}
102102
else
103103
{
@@ -110,10 +110,12 @@ internal void Walk(ISet<OpenApiTag>? tags)
110110
}
111111

112112
var context = index.ToString();
113-
WalkItem(context, tag, static (self, item) => self.Walk(item));
113+
WalkItem(context, tag, Walk);
114114
index++;
115115
}
116116
}
117+
118+
static void Walk(OpenApiWalker self, OpenApiTag tag) => self.Walk(tag);
117119
}
118120

119121
/// <summary>
@@ -131,7 +133,7 @@ internal void Walk(ISet<OpenApiTagReference>? tags)
131133
// Visit tags
132134
if (tags is HashSet<OpenApiTagReference> { Count: 1 } hashSet && hashSet.First() is { } only)
133135
{
134-
WalkItem("0", only, static (self, item) => self.Walk(item));
136+
WalkItem("0", only, Walk);
135137
}
136138
else
137139
{
@@ -144,10 +146,12 @@ internal void Walk(ISet<OpenApiTagReference>? tags)
144146
}
145147

146148
var context = index.ToString();
147-
WalkItem(context, tag, static (self, item) => self.Walk(item));
149+
WalkItem(context, tag, Walk);
148150
index++;
149151
}
150152
}
153+
154+
static void Walk(OpenApiWalker self, OpenApiTagReference tag) => self.Walk(tag);
151155
}
152156

153157
/// <summary>
@@ -1313,16 +1317,13 @@ internal void Walk(IOpenApiElement element)
13131317
}
13141318
}
13151319

1316-
/// <summary>
1317-
/// Adds a segment to the context path to enable pointing to the current location in the document
1318-
/// </summary>
1319-
/// <param name="context">An identifier for the context.</param>
1320-
/// <param name="walk">An action that walks objects within the context.</param>
1321-
private void Walk(string context, Action walk)
1320+
private static string ReplaceSlashes(string value)
13221321
{
1323-
_visitor.Enter(context.Replace("/", "~1"));
1324-
walk();
1325-
_visitor.Exit();
1322+
#if NET8_0_OR_GREATER
1323+
return value.Replace("/", "~1", StringComparison.Ordinal);
1324+
#else
1325+
return value.Replace("/", "~1");
1326+
#endif
13261327
}
13271328

13281329
/// <summary>
@@ -1334,7 +1335,7 @@ private void Walk(string context, Action walk)
13341335
/// <param name="walk">An action that walks objects within the context.</param>
13351336
private void WalkItem<T>(string context, T state, Action<OpenApiWalker, T> walk)
13361337
{
1337-
_visitor.Enter(context.Replace("/", "~1"));
1338+
_visitor.Enter(ReplaceSlashes(context));
13381339
walk(this, state);
13391340
_visitor.Exit();
13401341
}
@@ -1349,7 +1350,7 @@ private void WalkItem<T>(string context, T state, Action<OpenApiWalker, T> walk)
13491350
/// <param name="walk">An action that walks objects within the context.</param>
13501351
private void WalkItem<T>(string context, T state, Action<OpenApiWalker, T, bool> walk, bool isComponent)
13511352
{
1352-
_visitor.Enter(context.Replace("/", "~1"));
1353+
_visitor.Enter(ReplaceSlashes(context));
13531354
walk(this, state, isComponent);
13541355
_visitor.Exit();
13551356
}
@@ -1370,7 +1371,7 @@ private void WalkDictionary<T>(
13701371
{
13711372
if (state != null && state.Count > 0)
13721373
{
1373-
_visitor.Enter(context.Replace("/", "~1"));
1374+
_visitor.Enter(ReplaceSlashes(context));
13741375

13751376
foreach (var item in state)
13761377
{

0 commit comments

Comments
 (0)