@@ -19,8 +19,6 @@ public class OpenApiWalker
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 ;
23
-
24
22
/// <summary>
25
23
/// Initializes the <see cref="OpenApiWalker"/> class.
26
24
/// </summary>
@@ -42,7 +40,6 @@ public void Walk(OpenApiDocument doc)
42
40
43
41
_schemaLoop . Clear ( ) ;
44
42
_pathItemLoop . Clear ( ) ;
45
- _inComponents = false ;
46
43
47
44
_visitor . Visit ( doc ) ;
48
45
@@ -102,8 +99,6 @@ internal void Walk(OpenApiComponents components)
102
99
return ;
103
100
}
104
101
105
- EnterComponents ( ) ;
106
-
107
102
_visitor . Visit ( components ) ;
108
103
109
104
if ( components == null )
@@ -117,7 +112,7 @@ internal void Walk(OpenApiComponents components)
117
112
{
118
113
foreach ( var item in components . Schemas )
119
114
{
120
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
115
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
121
116
}
122
117
}
123
118
} ) ;
@@ -128,7 +123,7 @@ internal void Walk(OpenApiComponents components)
128
123
{
129
124
foreach ( var item in components . Callbacks )
130
125
{
131
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
126
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
132
127
}
133
128
}
134
129
} ) ;
@@ -139,7 +134,7 @@ internal void Walk(OpenApiComponents components)
139
134
{
140
135
foreach ( var item in components . Parameters )
141
136
{
142
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
137
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
143
138
}
144
139
}
145
140
} ) ;
@@ -150,7 +145,7 @@ internal void Walk(OpenApiComponents components)
150
145
{
151
146
foreach ( var item in components . Examples )
152
147
{
153
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
148
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
154
149
}
155
150
}
156
151
} ) ;
@@ -161,7 +156,7 @@ internal void Walk(OpenApiComponents components)
161
156
{
162
157
foreach ( var item in components . Headers )
163
158
{
164
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
159
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
165
160
}
166
161
}
167
162
} ) ;
@@ -172,7 +167,7 @@ internal void Walk(OpenApiComponents components)
172
167
{
173
168
foreach ( var item in components . Links )
174
169
{
175
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
170
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
176
171
}
177
172
}
178
173
} ) ;
@@ -183,7 +178,7 @@ internal void Walk(OpenApiComponents components)
183
178
{
184
179
foreach ( var item in components . RequestBodies )
185
180
{
186
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
181
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
187
182
}
188
183
}
189
184
} ) ;
@@ -194,13 +189,12 @@ internal void Walk(OpenApiComponents components)
194
189
{
195
190
foreach ( var item in components . Responses )
196
191
{
197
- Walk ( item . Key , ( ) => Walk ( item . Value ) ) ;
192
+ Walk ( item . Key , ( ) => Walk ( item . Value , true ) ) ;
198
193
}
199
194
}
200
195
} ) ;
201
196
202
197
Walk ( components as IOpenApiExtensible ) ;
203
- ExitComponents ( ) ;
204
198
}
205
199
206
200
/// <summary>
@@ -332,20 +326,13 @@ internal void Walk(OpenApiContact contact)
332
326
/// <summary>
333
327
/// Visits <see cref="OpenApiCallback"/> and child objects
334
328
/// </summary>
335
- internal void Walk ( OpenApiCallback callback )
329
+ internal void Walk ( OpenApiCallback callback , bool isComponent = false )
336
330
{
337
- if ( callback == null )
331
+ if ( callback == null || IsReference ( callback , isComponent ) )
338
332
{
339
333
return ;
340
334
}
341
335
342
- var isAComponent = false ; // Handle $refs within component
343
- if ( _inComponents )
344
- {
345
- isAComponent = true ;
346
- ExitComponents ( ) ;
347
- }
348
-
349
336
_visitor . Visit ( callback ) ;
350
337
351
338
if ( callback != null )
@@ -358,11 +345,6 @@ internal void Walk(OpenApiCallback callback)
358
345
_visitor . CurrentKeys . Callback = null ;
359
346
}
360
347
}
361
-
362
- if ( isAComponent )
363
- {
364
- EnterComponents ( ) ;
365
- }
366
348
}
367
349
368
350
/// <summary>
@@ -553,31 +535,19 @@ internal void Walk(IList<OpenApiParameter> parameters)
553
535
/// <summary>
554
536
/// Visits <see cref="OpenApiParameter"/> and child objects
555
537
/// </summary>
556
- internal void Walk ( OpenApiParameter parameter )
538
+ internal void Walk ( OpenApiParameter parameter , bool isComponent = false )
557
539
{
558
- if ( parameter == null || IsReference ( parameter ) )
540
+ if ( parameter == null || IsReference ( parameter , isComponent ) )
559
541
{
560
542
return ;
561
543
}
562
544
563
- var isAComponent = false ; // Handle $refs within component
564
- if ( _inComponents )
565
- {
566
- isAComponent = true ;
567
- ExitComponents ( ) ;
568
- }
569
-
570
545
_visitor . Visit ( parameter ) ;
571
546
Walk ( OpenApiConstants . Schema , ( ) => Walk ( parameter . Schema ) ) ;
572
547
Walk ( OpenApiConstants . Content , ( ) => Walk ( parameter . Content ) ) ;
573
548
Walk ( OpenApiConstants . Examples , ( ) => Walk ( parameter . Examples ) ) ;
574
549
575
550
Walk ( parameter as IOpenApiExtensible ) ;
576
-
577
- if ( isAComponent )
578
- {
579
- EnterComponents ( ) ;
580
- }
581
551
}
582
552
583
553
/// <summary>
@@ -607,47 +577,29 @@ internal void Walk(OpenApiResponses responses)
607
577
/// <summary>
608
578
/// Visits <see cref="OpenApiResponse"/> and child objects
609
579
/// </summary>
610
- internal void Walk ( OpenApiResponse response )
580
+ internal void Walk ( OpenApiResponse response , bool isComponent = false )
611
581
{
612
- if ( response == null || IsReference ( response ) )
582
+ if ( response == null || IsReference ( response , isComponent ) )
613
583
{
614
584
return ;
615
585
}
616
586
617
- var isAComponent = false ; // Handle $refs within component
618
- if ( _inComponents )
619
- {
620
- isAComponent = true ;
621
- ExitComponents ( ) ;
622
- }
623
-
624
587
_visitor . Visit ( response ) ;
625
588
Walk ( OpenApiConstants . Content , ( ) => Walk ( response . Content ) ) ;
626
589
Walk ( OpenApiConstants . Links , ( ) => Walk ( response . Links ) ) ;
627
590
Walk ( OpenApiConstants . Headers , ( ) => Walk ( response . Headers ) ) ;
628
591
Walk ( response as IOpenApiExtensible ) ;
629
-
630
- if ( isAComponent )
631
- {
632
- EnterComponents ( ) ;
633
- }
634
592
}
635
593
636
594
/// <summary>
637
595
/// Visits <see cref="OpenApiRequestBody"/> and child objects
638
596
/// </summary>
639
- internal void Walk ( OpenApiRequestBody requestBody )
597
+ internal void Walk ( OpenApiRequestBody requestBody , bool isComponent = false )
640
598
{
641
- if ( requestBody == null || IsReference ( requestBody ) )
599
+ if ( requestBody == null || IsReference ( requestBody , isComponent ) )
642
600
{
643
601
return ;
644
602
}
645
- var isAComponent = false ; // Handle $refs within component
646
- if ( _inComponents )
647
- {
648
- isAComponent = true ;
649
- ExitComponents ( ) ;
650
- }
651
603
652
604
_visitor . Visit ( requestBody ) ;
653
605
@@ -659,11 +611,6 @@ internal void Walk(OpenApiRequestBody requestBody)
659
611
}
660
612
}
661
613
Walk ( requestBody as IOpenApiExtensible ) ;
662
-
663
- if ( isAComponent )
664
- {
665
- EnterComponents ( ) ;
666
- }
667
614
}
668
615
669
616
/// <summary>
@@ -790,18 +737,12 @@ internal void Walk(OpenApiEncoding encoding)
790
737
/// <summary>
791
738
/// Visits <see cref="OpenApiSchema"/> and child objects
792
739
/// </summary>
793
- internal void Walk ( OpenApiSchema schema )
740
+ internal void Walk ( OpenApiSchema schema , bool isComponent = false )
794
741
{
795
- if ( schema == null || IsReference ( schema ) )
742
+ if ( schema == null || IsReference ( schema , isComponent ) )
796
743
{
797
744
return ;
798
745
}
799
- var isAComponent = false ; // Handle $refs within component
800
- if ( _inComponents )
801
- {
802
- isAComponent = true ;
803
- ExitComponents ( ) ;
804
- }
805
746
806
747
if ( _schemaLoop . Contains ( schema ) )
807
748
{
@@ -842,11 +783,6 @@ internal void Walk(OpenApiSchema schema)
842
783
Walk ( schema as IOpenApiExtensible ) ;
843
784
844
785
_schemaLoop . Pop ( ) ;
845
-
846
- if ( isAComponent )
847
- {
848
- EnterComponents ( ) ;
849
- }
850
786
}
851
787
852
788
/// <summary>
@@ -888,9 +824,9 @@ internal void Walk(IOpenApiAny example)
888
824
/// <summary>
889
825
/// Visits <see cref="OpenApiExample"/> and child objects
890
826
/// </summary>
891
- internal void Walk ( OpenApiExample example )
827
+ internal void Walk ( OpenApiExample example , bool isComponent = false )
892
828
{
893
- if ( example == null || IsReference ( example ) )
829
+ if ( example == null || IsReference ( example , isComponent ) )
894
830
{
895
831
return ;
896
832
}
@@ -994,9 +930,9 @@ internal void Walk(IDictionary<string,OpenApiLink> links)
994
930
/// <summary>
995
931
/// Visits <see cref="OpenApiLink"/> and child objects
996
932
/// </summary>
997
- internal void Walk ( OpenApiLink link )
933
+ internal void Walk ( OpenApiLink link , bool isComponent = false )
998
934
{
999
- if ( link == null || IsReference ( link ) )
935
+ if ( link == null || IsReference ( link , isComponent ) )
1000
936
{
1001
937
return ;
1002
938
}
@@ -1009,30 +945,19 @@ internal void Walk(OpenApiLink link)
1009
945
/// <summary>
1010
946
/// Visits <see cref="OpenApiHeader"/> and child objects
1011
947
/// </summary>
1012
- internal void Walk ( OpenApiHeader header )
948
+ internal void Walk ( OpenApiHeader header , bool isComponent = false )
1013
949
{
1014
- if ( header == null || IsReference ( header ) )
950
+ if ( header == null || IsReference ( header , isComponent ) )
1015
951
{
1016
952
return ;
1017
953
}
1018
- var isAComponent = false ; // Handle $refs within component
1019
- if ( _inComponents )
1020
- {
1021
- isAComponent = true ;
1022
- ExitComponents ( ) ;
1023
- }
1024
954
1025
955
_visitor . Visit ( header ) ;
1026
956
Walk ( OpenApiConstants . Content , ( ) => Walk ( header . Content ) ) ;
1027
957
Walk ( OpenApiConstants . Example , ( ) => Walk ( header . Example ) ) ;
1028
958
Walk ( OpenApiConstants . Examples , ( ) => Walk ( header . Examples ) ) ;
1029
959
Walk ( OpenApiConstants . Schema , ( ) => Walk ( header . Schema ) ) ;
1030
960
Walk ( header as IOpenApiExtensible ) ;
1031
-
1032
- if ( isAComponent )
1033
- {
1034
- EnterComponents ( ) ;
1035
- }
1036
961
}
1037
962
1038
963
/// <summary>
@@ -1131,25 +1056,15 @@ private void Walk(string context, Action walk)
1131
1056
/// <summary>
1132
1057
/// Identify if an element is just a reference to a component, or an actual component
1133
1058
/// </summary>
1134
- private bool IsReference ( IOpenApiReferenceable referenceable )
1059
+ private bool IsReference ( IOpenApiReferenceable referenceable , bool isComponent = false )
1135
1060
{
1136
- var isReference = referenceable . Reference != null && ! _inComponents ;
1061
+ var isReference = referenceable . Reference != null && ! isComponent ;
1137
1062
if ( isReference )
1138
1063
{
1139
1064
Walk ( referenceable ) ;
1140
1065
}
1141
1066
return isReference ;
1142
1067
}
1143
-
1144
- private void EnterComponents ( )
1145
- {
1146
- _inComponents = true ;
1147
- }
1148
-
1149
- private void ExitComponents ( )
1150
- {
1151
- _inComponents = false ;
1152
- }
1153
1068
}
1154
1069
1155
1070
/// <summary>
0 commit comments