Skip to content

Commit d455059

Browse files
committed
Fixes based on code review
1 parent de1c5fa commit d455059

File tree

2 files changed

+59
-32
lines changed

2 files changed

+59
-32
lines changed

src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,11 @@ namespace Microsoft.OpenApi.Services
1515
public abstract class OpenApiVisitorBase
1616
{
1717
private readonly Stack<string> _path = new Stack<string>();
18-
private CurrentKeys _currentKeys = new CurrentKeys();
19-
20-
2118

2219
/// <summary>
2320
/// Properties available to identify context of where an object is within OpenAPI Document
2421
/// </summary>
25-
public CurrentKeys CurrentKeys
26-
{
27-
get
28-
{
29-
return _currentKeys;
30-
}
31-
}
22+
public CurrentKeys CurrentKeys { get; } = new CurrentKeys();
3223

3324
/// <summary>
3425
/// Allow Rule to indicate validation error occured at a deeper context level.
@@ -58,17 +49,6 @@ public string PathString
5849
}
5950
}
6051

61-
internal void AttachCurrentKeys(CurrentKeys currentKeys)
62-
{
63-
64-
}
65-
66-
internal void ClearCurrentKeys()
67-
{
68-
69-
}
70-
71-
7252
/// <summary>
7353
/// Visits <see cref="OpenApiDocument"/>
7454
/// </summary>

src/Microsoft.OpenApi/Services/OpenApiWalker.cs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ internal void Walk(OpenApiPaths paths)
222222
{
223223
_visitor.CurrentKeys.Path = pathItem.Key;
224224
Walk(pathItem.Key, () => Walk(pathItem.Value));// JSON Pointer uses ~1 as an escape character for /
225+
_visitor.CurrentKeys.Path = null;
225226
}
226-
_visitor.CurrentKeys.Path = null;
227227
}
228228
}
229229

@@ -285,8 +285,8 @@ internal void Walk(IOpenApiExtensible openApiExtensible)
285285
{
286286
_visitor.CurrentKeys.Extension = item.Key;
287287
Walk(item.Key, () => Walk(item.Value));
288+
_visitor.CurrentKeys.Extension = null;
288289
}
289-
_visitor.CurrentKeys.Extension = null;
290290
}
291291
}
292292

@@ -348,8 +348,8 @@ internal void Walk(OpenApiCallback callback)
348348
_visitor.CurrentKeys.Callback = item.Key.ToString();
349349
var pathItem = item.Value;
350350
Walk(item.Key.ToString(), () => Walk(pathItem));
351+
_visitor.CurrentKeys.Callback = null;
351352
}
352-
_visitor.CurrentKeys.Callback = null;
353353
}
354354
}
355355

@@ -401,8 +401,8 @@ internal void Walk(IDictionary<string,OpenApiServerVariable> serverVariables)
401401
{
402402
_visitor.CurrentKeys.ServerVariable = variable.Key;
403403
Walk(variable.Key, () => Walk(variable.Value));
404+
_visitor.CurrentKeys.ServerVariable = null;
404405
}
405-
_visitor.CurrentKeys.ServerVariable = null;
406406
}
407407
}
408408

@@ -468,8 +468,8 @@ internal void Walk(IDictionary<OperationType, OpenApiOperation> operations)
468468
{
469469
_visitor.CurrentKeys.Operation = operation.Key;
470470
Walk(operation.Key.GetDisplayName(), () => Walk(operation.Value));
471+
_visitor.CurrentKeys.Operation = null;
471472
}
472-
_visitor.CurrentKeys.Operation = null;
473473
}
474474
}
475475

@@ -574,8 +574,8 @@ internal void Walk(OpenApiResponses responses)
574574
{
575575
_visitor.CurrentKeys.Response = response.Key;
576576
Walk(response.Key, () => Walk(response.Value));
577+
_visitor.CurrentKeys.Response = null;
577578
}
578-
_visitor.CurrentKeys.Response = null;
579579
}
580580
Walk(responses as IOpenApiExtensible);
581581
}
@@ -637,8 +637,8 @@ internal void Walk(IDictionary<string, OpenApiHeader> headers)
637637
{
638638
_visitor.CurrentKeys.Header = header.Key;
639639
Walk(header.Key, () => Walk(header.Value));
640+
_visitor.CurrentKeys.Header = null;
640641
}
641-
_visitor.CurrentKeys.Header = null;
642642
}
643643
}
644644

@@ -659,8 +659,8 @@ internal void Walk(IDictionary<string, OpenApiCallback> callbacks)
659659
{
660660
_visitor.CurrentKeys.Callback = callback.Key;
661661
Walk(callback.Key, () => Walk(callback.Value));
662+
_visitor.CurrentKeys.Callback = null;
662663
}
663-
_visitor.CurrentKeys.Callback = null;
664664
}
665665
}
666666

@@ -681,8 +681,8 @@ internal void Walk(IDictionary<string, OpenApiMediaType> content)
681681
{
682682
_visitor.CurrentKeys.Content = mediaType.Key;
683683
Walk(mediaType.Key, () => Walk(mediaType.Value));
684+
_visitor.CurrentKeys.Content = null;
684685
}
685-
_visitor.CurrentKeys.Content = null;
686686
}
687687
}
688688

@@ -722,8 +722,8 @@ internal void Walk(IDictionary<string, OpenApiEncoding> encodings)
722722
{
723723
_visitor.CurrentKeys.Encoding = item.Key;
724724
Walk(item.Key, () => Walk(item.Value));
725+
_visitor.CurrentKeys.Encoding = null;
725726
}
726-
_visitor.CurrentKeys.Encoding = null;
727727
}
728728
}
729729

@@ -810,6 +810,7 @@ internal void Walk(IDictionary<string,OpenApiExample> examples)
810810
{
811811
_visitor.CurrentKeys.Example = example.Key;
812812
Walk(example.Key, () => Walk(example.Value));
813+
_visitor.CurrentKeys.Example = null;
813814
}
814815
}
815816
}
@@ -928,8 +929,8 @@ internal void Walk(IDictionary<string,OpenApiLink> links)
928929
{
929930
_visitor.CurrentKeys.Link = item.Key;
930931
Walk(item.Key, () => Walk(item.Value));
932+
_visitor.CurrentKeys.Link = null;
931933
}
932-
_visitor.CurrentKeys.Link = null;
933934
}
934935
}
935936

@@ -1070,18 +1071,64 @@ private void ExitComponents()
10701071
}
10711072
}
10721073

1074+
/// <summary>
1075+
/// Object containing contextual information based on where the walker is currently referencing in an OpenApiDocument
1076+
/// </summary>
10731077
public class CurrentKeys
10741078
{
1079+
/// <summary>
1080+
/// Current Path key
1081+
/// </summary>
10751082
public string Path { get; set; }
1083+
1084+
/// <summary>
1085+
/// Current Operation Type
1086+
/// </summary>
10761087
public OperationType? Operation { get; set; }
1088+
1089+
/// <summary>
1090+
/// Current Response Status Code
1091+
/// </summary>
10771092
public string Response { get; set; }
1093+
1094+
/// <summary>
1095+
/// Current Content Media Type
1096+
/// </summary>
10781097
public string Content { get; set; }
1098+
1099+
/// <summary>
1100+
/// Current Callback Key
1101+
/// </summary>
10791102
public string Callback { get; set; }
1103+
1104+
/// <summary>
1105+
/// Current Link Key
1106+
/// </summary>
10801107
public string Link { get; set; }
1108+
1109+
/// <summary>
1110+
/// Current Header Key
1111+
/// </summary>
10811112
public string Header { get; internal set; }
1113+
1114+
/// <summary>
1115+
/// Current Encoding Key
1116+
/// </summary>
10821117
public string Encoding { get; internal set; }
1118+
1119+
/// <summary>
1120+
/// Current Example Key
1121+
/// </summary>
10831122
public string Example { get; internal set; }
1123+
1124+
/// <summary>
1125+
/// Current Extension Key
1126+
/// </summary>
10841127
public string Extension { get; internal set; }
1128+
1129+
/// <summary>
1130+
/// Current ServerVariable
1131+
/// </summary>
10851132
public string ServerVariable { get; internal set; }
10861133
}
10871134
}

0 commit comments

Comments
 (0)