@@ -18,7 +18,6 @@ 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
- private Dictionary < string , string > _currentKeys = new Dictionary < string , string > ( ) ;
22
21
23
22
private bool _inComponents = false ;
24
23
@@ -55,6 +54,7 @@ public void Walk(OpenApiDocument doc)
55
54
Walk ( OpenApiConstants . ExternalDocs , ( ) => Walk ( doc . ExternalDocs ) ) ;
56
55
Walk ( OpenApiConstants . Tags , ( ) => Walk ( doc . Tags ) ) ;
57
56
Walk ( doc as IOpenApiExtensible ) ;
57
+
58
58
}
59
59
60
60
/// <summary>
@@ -77,7 +77,6 @@ internal void Walk(IList<OpenApiTag> tags)
77
77
Walk ( i . ToString ( ) , ( ) => Walk ( tags [ i ] ) ) ;
78
78
}
79
79
}
80
-
81
80
}
82
81
83
82
/// <summary>
@@ -221,8 +220,10 @@ internal void Walk(OpenApiPaths paths)
221
220
{
222
221
foreach ( var pathItem in paths )
223
222
{
223
+ _visitor . CurrentKeys . Path = pathItem . Key ;
224
224
Walk ( pathItem . Key , ( ) => Walk ( pathItem . Value ) ) ; // JSON Pointer uses ~1 as an escape character for /
225
225
}
226
+ _visitor . CurrentKeys . Path = null ;
226
227
}
227
228
}
228
229
@@ -282,8 +283,10 @@ internal void Walk(IOpenApiExtensible openApiExtensible)
282
283
{
283
284
foreach ( var item in openApiExtensible . Extensions )
284
285
{
286
+ _visitor . CurrentKeys . Extension = item . Key ;
285
287
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
286
288
}
289
+ _visitor . CurrentKeys . Extension = null ;
287
290
}
288
291
}
289
292
@@ -342,9 +345,11 @@ internal void Walk(OpenApiCallback callback)
342
345
{
343
346
foreach ( var item in callback . PathItems )
344
347
{
348
+ _visitor . CurrentKeys . Callback = item . Key . ToString ( ) ;
345
349
var pathItem = item . Value ;
346
350
Walk ( item . Key . ToString ( ) , ( ) => Walk ( pathItem ) ) ;
347
351
}
352
+ _visitor . CurrentKeys . Callback = null ;
348
353
}
349
354
}
350
355
@@ -394,8 +399,10 @@ internal void Walk(IDictionary<string,OpenApiServerVariable> serverVariables)
394
399
{
395
400
foreach ( var variable in serverVariables )
396
401
{
402
+ _visitor . CurrentKeys . ServerVariable = variable . Key ;
397
403
Walk ( variable . Key , ( ) => Walk ( variable . Value ) ) ;
398
404
}
405
+ _visitor . CurrentKeys . ServerVariable = null ;
399
406
}
400
407
}
401
408
@@ -459,8 +466,10 @@ internal void Walk(IDictionary<OperationType, OpenApiOperation> operations)
459
466
{
460
467
foreach ( var operation in operations )
461
468
{
469
+ _visitor . CurrentKeys . Operation = operation . Key ;
462
470
Walk ( operation . Key . GetDisplayName ( ) , ( ) => Walk ( operation . Value ) ) ;
463
471
}
472
+ _visitor . CurrentKeys . Operation = null ;
464
473
}
465
474
}
466
475
@@ -563,8 +572,10 @@ internal void Walk(OpenApiResponses responses)
563
572
{
564
573
foreach ( var response in responses )
565
574
{
575
+ _visitor . CurrentKeys . Response = response . Key ;
566
576
Walk ( response . Key , ( ) => Walk ( response . Value ) ) ;
567
577
}
578
+ _visitor . CurrentKeys . Response = null ;
568
579
}
569
580
Walk ( responses as IOpenApiExtensible ) ;
570
581
}
@@ -624,8 +635,10 @@ internal void Walk(IDictionary<string, OpenApiHeader> headers)
624
635
{
625
636
foreach ( var header in headers )
626
637
{
638
+ _visitor . CurrentKeys . Header = header . Key ;
627
639
Walk ( header . Key , ( ) => Walk ( header . Value ) ) ;
628
640
}
641
+ _visitor . CurrentKeys . Header = null ;
629
642
}
630
643
}
631
644
@@ -642,10 +655,12 @@ internal void Walk(IDictionary<string, OpenApiCallback> callbacks)
642
655
_visitor . Visit ( callbacks ) ;
643
656
if ( callbacks != null )
644
657
{
645
- foreach ( var header in callbacks )
658
+ foreach ( var callback in callbacks )
646
659
{
647
- Walk ( header . Key , ( ) => Walk ( header . Value ) ) ;
660
+ _visitor . CurrentKeys . Callback = callback . Key ;
661
+ Walk ( callback . Key , ( ) => Walk ( callback . Value ) ) ;
648
662
}
663
+ _visitor . CurrentKeys . Callback = null ;
649
664
}
650
665
}
651
666
@@ -664,8 +679,10 @@ internal void Walk(IDictionary<string, OpenApiMediaType> content)
664
679
{
665
680
foreach ( var mediaType in content )
666
681
{
682
+ _visitor . CurrentKeys . Content = mediaType . Key ;
667
683
Walk ( mediaType . Key , ( ) => Walk ( mediaType . Value ) ) ;
668
684
}
685
+ _visitor . CurrentKeys . Content = null ;
669
686
}
670
687
}
671
688
@@ -703,8 +720,10 @@ internal void Walk(IDictionary<string, OpenApiEncoding> encodings)
703
720
{
704
721
foreach ( var item in encodings )
705
722
{
723
+ _visitor . CurrentKeys . Encoding = item . Key ;
706
724
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
707
725
}
726
+ _visitor . CurrentKeys . Encoding = null ;
708
727
}
709
728
}
710
729
@@ -789,6 +808,7 @@ internal void Walk(IDictionary<string,OpenApiExample> examples)
789
808
{
790
809
foreach ( var example in examples )
791
810
{
811
+ _visitor . CurrentKeys . Example = example . Key ;
792
812
Walk ( example . Key , ( ) => Walk ( example . Value ) ) ;
793
813
}
794
814
}
@@ -906,8 +926,10 @@ internal void Walk(IDictionary<string,OpenApiLink> links)
906
926
{
907
927
foreach ( var item in links )
908
928
{
929
+ _visitor . CurrentKeys . Link = item . Key ;
909
930
Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
910
931
}
932
+ _visitor . CurrentKeys . Link = null ;
911
933
}
912
934
}
913
935
@@ -1047,4 +1069,19 @@ private void ExitComponents()
1047
1069
_inComponents = false ;
1048
1070
}
1049
1071
}
1072
+
1073
+ public class CurrentKeys
1074
+ {
1075
+ public string Path { get ; set ; }
1076
+ public OperationType ? Operation { get ; set ; }
1077
+ public string Response { get ; set ; }
1078
+ public string Content { get ; set ; }
1079
+ public string Callback { get ; set ; }
1080
+ public string Link { get ; set ; }
1081
+ public string Header { get ; internal set ; }
1082
+ public string Encoding { get ; internal set ; }
1083
+ public string Example { get ; internal set ; }
1084
+ public string Extension { get ; internal set ; }
1085
+ public string ServerVariable { get ; internal set ; }
1086
+ }
1050
1087
}
0 commit comments