Skip to content

Commit fdb1fbf

Browse files
committed
Add test
1 parent 779060f commit fdb1fbf

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\documentWithReusablePaths.yaml">
129129
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
130130
</EmbeddedResource>
131+
<EmbeddedResource Include="V3Tests\Samples\OpenApiDocument\documentWithSummaryAndDescriptionInReference.yaml">
132+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
133+
</EmbeddedResource>
131134
<EmbeddedResource Include="V3Tests\Samples\OpenApiDiscriminator\basicDiscriminator.yaml">
132135
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
133136
</EmbeddedResource>

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.OpenApi.Writers;
1717
using Xunit;
1818
using Xunit.Abstractions;
19+
using Xunit.Sdk;
20+
using static System.Net.Mime.MediaTypeNames;
1921

2022
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
2123
{
@@ -1777,5 +1779,22 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
17771779
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
17781780

17791781
}
1782+
1783+
[Fact]
1784+
public void ParseDocumentWithDescriptionInDollarRefsShouldSucceed()
1785+
{
1786+
// Arrange
1787+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "documentWithSummaryAndDescriptionInReference.yaml"));
1788+
1789+
// Act
1790+
var actual = new OpenApiStreamReader().Read(stream, out var diagnostic);
1791+
var schema = actual.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
1792+
var header = actual.Components.Responses["Test"].Headers["X-Test"];
1793+
1794+
// Assert
1795+
Assert.True(header.Description == "A referenced X-Test header"); /*response header #ref's description overrides the header's description*/
1796+
Assert.True(schema.UnresolvedReference == false && schema.Type == "object"); /*schema reference is resolved*/
1797+
Assert.Equal("A pet in a petstore", schema.Description); /*The reference object's description overrides that of the referenced component*/
1798+
}
17801799
}
17811800
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
openapi: '3.1.0'
2+
info:
3+
version: '1.0.0'
4+
title: Swagger Petstore (Simple)
5+
paths:
6+
/pets:
7+
get:
8+
description: Returns all pets from the system that the user has access to
9+
responses:
10+
'200':
11+
description: pet response
12+
content:
13+
application/json:
14+
schema:
15+
"$ref": '#/components/schemas/pet'
16+
summary: A pet
17+
description: A pet in a petstore
18+
components:
19+
headers:
20+
X-Test:
21+
description: Test
22+
schema:
23+
type: string
24+
responses:
25+
Test:
26+
description: Test Repsonse
27+
headers:
28+
X-Test:
29+
$ref: '#/components/headers/X-Test'
30+
summary: X-Test header
31+
description: A referenced X-Test header
32+
schemas:
33+
pet:
34+
description: A referenced pet in a petstore
35+
type: object
36+
required:
37+
- id
38+
- name
39+
properties:
40+
id:
41+
type: integer
42+
format: int64
43+
name:
44+
type: string
45+
tag:
46+
type: string

0 commit comments

Comments
 (0)