Skip to content

Commit 5078a58

Browse files
committed
Cleanup to ParsingContext
1 parent c60b007 commit 5078a58

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class ParsingContext
2020
private readonly Stack<string> _currentLocation = new Stack<string>();
2121
private readonly Dictionary<string, IOpenApiReferenceable> _referenceStore = new Dictionary<string, IOpenApiReferenceable>();
2222
private readonly Dictionary<string, object> _tempStorage = new Dictionary<string, object>();
23-
private readonly List<OpenApiTag> _tags = new List<OpenApiTag>();
2423
private IOpenApiVersionService _versionService;
25-
private RootNode _rootNode;
24+
internal RootNode RootNode { get; set; }
25+
internal List<OpenApiTag> Tags { get; private set; } = new List<OpenApiTag>();
2626

2727

2828
/// <summary>
@@ -33,48 +33,27 @@ public class ParsingContext
3333
/// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns>
3434
internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diagnostic)
3535
{
36-
_rootNode = new RootNode(this, diagnostic, yamlDocument);
36+
RootNode = new RootNode(this, diagnostic, yamlDocument);
3737

38-
var inputVersion = GetVersion(_rootNode);
38+
var inputVersion = GetVersion(RootNode);
3939

4040
OpenApiDocument doc;
4141
switch (inputVersion)
4242
{
4343
case "2.0":
4444
this.ReferenceService = new OpenApiV2VersionService();
45-
doc = this.ReferenceService.LoadOpenApi(_rootNode);
45+
doc = this.ReferenceService.LoadOpenApi(RootNode);
4646
break;
4747

4848
default:
4949
this.ReferenceService = new OpenApiV3VersionService();
50-
doc = this.ReferenceService.LoadOpenApi(_rootNode);
50+
doc = this.ReferenceService.LoadOpenApi(RootNode);
5151
break;
5252
}
5353

5454
return doc;
5555
}
5656

57-
internal RootNode RootNode { get
58-
{
59-
return _rootNode;
60-
}
61-
set
62-
{
63-
{
64-
_rootNode = value;
65-
66-
}
67-
}
68-
}
69-
70-
internal List<OpenApiTag> Tags
71-
{
72-
get
73-
{
74-
return _tags;
75-
}
76-
}
77-
7857
/// <summary>
7958
/// Gets the version of the Open API document.
8059
/// </summary>
@@ -97,7 +76,7 @@ private void ComputeTags(List<OpenApiTag> tags, Func<MapNode,OpenApiTag> loadTag
9776
// Precompute the tags array so that each tag reference does not require a new deserialization.
9877
var tagListPointer = new JsonPointer("#/tags");
9978

100-
var tagListNode = _rootNode.Find(tagListPointer);
79+
var tagListNode = RootNode.Find(tagListPointer);
10180

10281
if (tagListNode != null && tagListNode is ListNode)
10382
{
@@ -112,19 +91,23 @@ private void ComputeTags(List<OpenApiTag> tags, Func<MapNode,OpenApiTag> loadTag
11291
/// <summary>
11392
/// Reference service.
11493
/// </summary>
115-
internal IOpenApiVersionService ReferenceService { get {
94+
internal IOpenApiVersionService ReferenceService
95+
{
96+
get
97+
{
11698
return _versionService;
11799
}
118-
set {
100+
set
101+
{
119102
_versionService = value;
120-
ComputeTags(_tags, ReferenceService.TagLoader);
103+
ComputeTags(Tags, ReferenceService.TagLoader);
121104
}
122105
}
123106

124-
/// <summary>
125-
/// End the current object.
126-
/// </summary>
127-
public void EndObject()
107+
/// <summary>
108+
/// End the current object.
109+
/// </summary>
110+
public void EndObject()
128111
{
129112
_currentLocation.Pop();
130113
}

0 commit comments

Comments
 (0)