Skip to content

Commit 13bf0aa

Browse files
committed
Moved _inComponents logic into Walker
1 parent e761861 commit 13bf0aa

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace Microsoft.OpenApi.Services
1515
public abstract class OpenApiVisitorBase
1616
{
1717
private readonly Stack<string> _path = new Stack<string>();
18-
private bool _inComponents = false;
1918

2019
/// <summary>
2120
/// Allow Rule to indicate validation error occured at a deeper context level.
@@ -34,16 +33,6 @@ public void Exit()
3433
this._path.Pop();
3534
}
3635

37-
public void EnterComponents()
38-
{
39-
_inComponents = true;
40-
}
41-
42-
public void ExitComponents()
43-
{
44-
_inComponents = false;
45-
}
46-
4736
/// <summary>
4837
/// Pointer to source of validation error in document
4938
/// </summary>
@@ -55,13 +44,7 @@ public string PathString
5544
}
5645
}
5746

58-
public bool InComponents
59-
{
60-
get
61-
{
62-
return _inComponents;
63-
}
64-
}
47+
6548

6649
/// <summary>
6750
/// Visits <see cref="OpenApiDocument"/>

src/Microsoft.OpenApi/Services/OpenApiWalker.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class OpenApiWalker
1818
private readonly OpenApiVisitorBase _visitor;
1919
private readonly Stack<OpenApiSchema> _schemaLoop = new Stack<OpenApiSchema>();
2020
private readonly Stack<OpenApiPathItem> _pathItemLoop = new Stack<OpenApiPathItem>();
21+
private bool _inComponents = false;
2122

2223
/// <summary>
2324
/// Initializes the <see cref="OpenApiWalker"/> class.
@@ -37,6 +38,9 @@ public void Walk(OpenApiDocument doc)
3738
{
3839
return;
3940
}
41+
_schemaLoop.Clear();
42+
_pathItemLoop.Clear();
43+
_inComponents = false;
4044

4145
_visitor.Visit(doc);
4246

@@ -96,7 +100,7 @@ internal void Walk(OpenApiComponents components)
96100
return;
97101
}
98102

99-
_visitor.EnterComponents();
103+
EnterComponents();
100104

101105
_visitor.Visit(components);
102106

@@ -194,7 +198,7 @@ internal void Walk(OpenApiComponents components)
194198
});
195199

196200
Walk(components as IOpenApiExtensible);
197-
_visitor.ExitComponents();
201+
ExitComponents();
198202
}
199203

200204
/// <summary>
@@ -1027,7 +1031,17 @@ private void Walk(string context, Action walk)
10271031
/// </summary>
10281032
private bool IsReference(IOpenApiReferenceable referenceable)
10291033
{
1030-
return referenceable.Reference != null && !_visitor.InComponents;
1034+
return referenceable.Reference != null && !_inComponents;
1035+
}
1036+
1037+
private void EnterComponents()
1038+
{
1039+
_inComponents = true;
1040+
}
1041+
1042+
private void ExitComponents()
1043+
{
1044+
_inComponents = false;
10311045
}
10321046
}
10331047
}

0 commit comments

Comments
 (0)