File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed
src/Microsoft.OpenApi.Readers/Services
test/Microsoft.OpenApi.Readers.Tests Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ public override void Visit(OpenApiComponents components)
5252 ResolveMap ( components . Examples ) ;
5353 ResolveMap ( components . Schemas ) ;
5454 ResolveMap ( components . SecuritySchemes ) ;
55+ ResolveMap ( components . Headers ) ;
5556 }
5657
5758 public override void Visit ( IDictionary < string , OpenApiCallback > callbacks )
@@ -99,6 +100,14 @@ public override void Visit(OpenApiResponses responses)
99100 ResolveMap ( responses ) ;
100101 }
101102
103+ /// <summary>
104+ /// Resolve all references to headers
105+ /// </summary>
106+ public override void Visit ( OpenApiResponse response )
107+ {
108+ ResolveMap ( response . Headers ) ;
109+ }
110+
102111 /// <summary>
103112 /// Resolve all references to SecuritySchemes
104113 /// </summary>
Original file line number Diff line number Diff line change 150150 <CopyToOutputDirectory >Never</CopyToOutputDirectory >
151151 </EmbeddedResource >
152152 <EmbeddedResource Include =" V3Tests\Samples\OpenApiExample\explicitString.yaml" />
153+ <EmbeddedResource Include =" V3Tests\Samples\OpenApiResponse\responseWithHeaderReference.yaml" />
153154 <EmbeddedResource Include =" V3Tests\Samples\OpenApiInfo\basicInfo.yaml" >
154155 <CopyToOutputDirectory >Never</CopyToOutputDirectory >
155156 </EmbeddedResource >
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT license.
3+
4+ using System . IO ;
5+ using System . Linq ;
6+ using FluentAssertions ;
7+ using Microsoft . OpenApi . Any ;
8+ using Microsoft . OpenApi . Models ;
9+ using Microsoft . OpenApi . Readers . ParseNodes ;
10+ using Microsoft . OpenApi . Readers . V3 ;
11+ using Xunit ;
12+
13+ namespace Microsoft . OpenApi . Readers . Tests . V3Tests
14+ {
15+ [ Collection ( "DefaultSettings" ) ]
16+ public class OpenApiResponseTests
17+ {
18+ private const string SampleFolderPath = "V3Tests/Samples/OpenApiResponse/" ;
19+
20+ [ Fact ]
21+ public void ResponseWithReferencedHeaderShouldReferenceComponent ( )
22+ {
23+ using ( var stream = Resources . GetStream ( Path . Combine ( SampleFolderPath , "responseWithHeaderReference.yaml" ) ) )
24+ {
25+ var openApiDoc = new OpenApiStreamReader ( ) . Read ( stream , out var diagnostic ) ;
26+
27+ var response = openApiDoc . Components . Responses [ "Test" ] ;
28+
29+ Assert . Same ( response . Headers . First ( ) . Value , openApiDoc . Components . Headers . First ( ) . Value ) ;
30+ }
31+ }
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ openapi : 3.0.0
2+ info :
3+ title : Example of response referencing a header
4+ version : 1.0.0
5+ components :
6+ headers :
7+ X-Test :
8+ description : Test
9+ schema :
10+ type : string
11+ responses :
12+ Test :
13+ description : Test Repsonse
14+ headers :
15+ X-Test :
16+ $ref : ' #/components/headers/X-Test'
You can’t perform that action at this time.
0 commit comments