@@ -18,6 +18,7 @@ public class OpenApiWalker
18
18
private readonly OpenApiVisitorBase _visitor ;
19
19
private readonly Stack < OpenApiSchema > _schemaLoop = new Stack < OpenApiSchema > ( ) ;
20
20
private readonly Stack < OpenApiPathItem > _pathItemLoop = new Stack < OpenApiPathItem > ( ) ;
21
+
21
22
private bool _inComponents = false ;
22
23
23
24
/// <summary>
@@ -53,6 +54,7 @@ public void Walk(OpenApiDocument doc)
53
54
Walk ( OpenApiConstants . ExternalDocs , ( ) => Walk ( doc . ExternalDocs ) ) ;
54
55
Walk ( OpenApiConstants . Tags , ( ) => Walk ( doc . Tags ) ) ;
55
56
Walk ( doc as IOpenApiExtensible ) ;
57
+
56
58
}
57
59
58
60
/// <summary>
@@ -75,7 +77,6 @@ internal void Walk(IList<OpenApiTag> tags)
75
77
Walk ( i . ToString ( ) , ( ) => Walk ( tags [ i ] ) ) ;
76
78
}
77
79
}
78
-
79
80
}
80
81
81
82
/// <summary>
@@ -219,7 +220,9 @@ internal void Walk(OpenApiPaths paths)
219
220
{
220
221
foreach ( var pathItem in paths )
221
222
{
223
+ _visitor . CurrentKeys . Path = pathItem . Key ;
222
224
Walk ( pathItem . Key , ( ) => Walk ( pathItem . Value ) ) ; // JSON Pointer uses ~1 as an escape character for /
225
+ _visitor . CurrentKeys . Path = null ;
223
226
}
224
227
}
225
228
}
@@ -280,7 +283,9 @@ internal void Walk(IOpenApiExtensible openApiExtensible)
280
283
{
281
284
foreach ( var item in openApiExtensible . Extensions )
282
285
{
286
+ _visitor . CurrentKeys . Extension = item . Key ;
283
287
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
288
+ _visitor . CurrentKeys . Extension = null ;
284
289
}
285
290
}
286
291
}
@@ -340,8 +345,10 @@ internal void Walk(OpenApiCallback callback)
340
345
{
341
346
foreach ( var item in callback . PathItems )
342
347
{
348
+ _visitor . CurrentKeys . Callback = item . Key . ToString ( ) ;
343
349
var pathItem = item . Value ;
344
350
Walk ( item . Key . ToString ( ) , ( ) => Walk ( pathItem ) ) ;
351
+ _visitor . CurrentKeys . Callback = null ;
345
352
}
346
353
}
347
354
}
@@ -392,7 +399,9 @@ internal void Walk(IDictionary<string,OpenApiServerVariable> serverVariables)
392
399
{
393
400
foreach ( var variable in serverVariables )
394
401
{
402
+ _visitor . CurrentKeys . ServerVariable = variable . Key ;
395
403
Walk ( variable . Key , ( ) => Walk ( variable . Value ) ) ;
404
+ _visitor . CurrentKeys . ServerVariable = null ;
396
405
}
397
406
}
398
407
}
@@ -457,7 +466,9 @@ internal void Walk(IDictionary<OperationType, OpenApiOperation> operations)
457
466
{
458
467
foreach ( var operation in operations )
459
468
{
469
+ _visitor . CurrentKeys . Operation = operation . Key ;
460
470
Walk ( operation . Key . GetDisplayName ( ) , ( ) => Walk ( operation . Value ) ) ;
471
+ _visitor . CurrentKeys . Operation = null ;
461
472
}
462
473
}
463
474
}
@@ -561,7 +572,9 @@ internal void Walk(OpenApiResponses responses)
561
572
{
562
573
foreach ( var response in responses )
563
574
{
575
+ _visitor . CurrentKeys . Response = response . Key ;
564
576
Walk ( response . Key , ( ) => Walk ( response . Value ) ) ;
577
+ _visitor . CurrentKeys . Response = null ;
565
578
}
566
579
}
567
580
Walk ( responses as IOpenApiExtensible ) ;
@@ -622,7 +635,9 @@ internal void Walk(IDictionary<string, OpenApiHeader> headers)
622
635
{
623
636
foreach ( var header in headers )
624
637
{
638
+ _visitor . CurrentKeys . Header = header . Key ;
625
639
Walk ( header . Key , ( ) => Walk ( header . Value ) ) ;
640
+ _visitor . CurrentKeys . Header = null ;
626
641
}
627
642
}
628
643
}
@@ -640,9 +655,11 @@ internal void Walk(IDictionary<string, OpenApiCallback> callbacks)
640
655
_visitor . Visit ( callbacks ) ;
641
656
if ( callbacks != null )
642
657
{
643
- foreach ( var header in callbacks )
658
+ foreach ( var callback in callbacks )
644
659
{
645
- Walk ( header . Key , ( ) => Walk ( header . Value ) ) ;
660
+ _visitor . CurrentKeys . Callback = callback . Key ;
661
+ Walk ( callback . Key , ( ) => Walk ( callback . Value ) ) ;
662
+ _visitor . CurrentKeys . Callback = null ;
646
663
}
647
664
}
648
665
}
@@ -662,7 +679,9 @@ internal void Walk(IDictionary<string, OpenApiMediaType> content)
662
679
{
663
680
foreach ( var mediaType in content )
664
681
{
682
+ _visitor . CurrentKeys . Content = mediaType . Key ;
665
683
Walk ( mediaType . Key , ( ) => Walk ( mediaType . Value ) ) ;
684
+ _visitor . CurrentKeys . Content = null ;
666
685
}
667
686
}
668
687
}
@@ -701,7 +720,9 @@ internal void Walk(IDictionary<string, OpenApiEncoding> encodings)
701
720
{
702
721
foreach ( var item in encodings )
703
722
{
723
+ _visitor . CurrentKeys . Encoding = item . Key ;
704
724
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
725
+ _visitor . CurrentKeys . Encoding = null ;
705
726
}
706
727
}
707
728
}
@@ -787,7 +808,9 @@ internal void Walk(IDictionary<string,OpenApiExample> examples)
787
808
{
788
809
foreach ( var example in examples )
789
810
{
811
+ _visitor . CurrentKeys . Example = example . Key ;
790
812
Walk ( example . Key , ( ) => Walk ( example . Value ) ) ;
813
+ _visitor . CurrentKeys . Example = null ;
791
814
}
792
815
}
793
816
}
@@ -904,7 +927,9 @@ internal void Walk(IDictionary<string,OpenApiLink> links)
904
927
{
905
928
foreach ( var item in links )
906
929
{
930
+ _visitor . CurrentKeys . Link = item . Key ;
907
931
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
932
+ _visitor . CurrentKeys . Link = null ;
908
933
}
909
934
}
910
935
}
@@ -1045,4 +1070,65 @@ private void ExitComponents()
1045
1070
_inComponents = false ;
1046
1071
}
1047
1072
}
1073
+
1074
+ /// <summary>
1075
+ /// Object containing contextual information based on where the walker is currently referencing in an OpenApiDocument
1076
+ /// </summary>
1077
+ public class CurrentKeys
1078
+ {
1079
+ /// <summary>
1080
+ /// Current Path key
1081
+ /// </summary>
1082
+ public string Path { get ; set ; }
1083
+
1084
+ /// <summary>
1085
+ /// Current Operation Type
1086
+ /// </summary>
1087
+ public OperationType ? Operation { get ; set ; }
1088
+
1089
+ /// <summary>
1090
+ /// Current Response Status Code
1091
+ /// </summary>
1092
+ public string Response { get ; set ; }
1093
+
1094
+ /// <summary>
1095
+ /// Current Content Media Type
1096
+ /// </summary>
1097
+ public string Content { get ; set ; }
1098
+
1099
+ /// <summary>
1100
+ /// Current Callback Key
1101
+ /// </summary>
1102
+ public string Callback { get ; set ; }
1103
+
1104
+ /// <summary>
1105
+ /// Current Link Key
1106
+ /// </summary>
1107
+ public string Link { get ; set ; }
1108
+
1109
+ /// <summary>
1110
+ /// Current Header Key
1111
+ /// </summary>
1112
+ public string Header { get ; internal set ; }
1113
+
1114
+ /// <summary>
1115
+ /// Current Encoding Key
1116
+ /// </summary>
1117
+ public string Encoding { get ; internal set ; }
1118
+
1119
+ /// <summary>
1120
+ /// Current Example Key
1121
+ /// </summary>
1122
+ public string Example { get ; internal set ; }
1123
+
1124
+ /// <summary>
1125
+ /// Current Extension Key
1126
+ /// </summary>
1127
+ public string Extension { get ; internal set ; }
1128
+
1129
+ /// <summary>
1130
+ /// Current ServerVariable
1131
+ /// </summary>
1132
+ public string ServerVariable { get ; internal set ; }
1133
+ }
1048
1134
}
0 commit comments