Skip to content

Commit 0b63d77

Browse files
committed
Add unit test to validate
1 parent f63443f commit 0b63d77

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using System.IO;
55
using FluentAssertions;
66
using Microsoft.OpenApi.Any;
7+
using Microsoft.OpenApi.Extensions;
78
using Microsoft.OpenApi.Models;
89
using Microsoft.OpenApi.Readers.ParseNodes;
910
using Microsoft.OpenApi.Readers.V3;
11+
using Microsoft.OpenApi.Tests;
1012
using Xunit;
1113

1214
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
@@ -77,5 +79,43 @@ public void ParseMediaTypeWithExamplesShouldSucceed()
7779
}
7880
});
7981
}
82+
83+
[Fact]
84+
public void ParseMediaTypeWithEmptyArrayInExamplesWorks()
85+
{
86+
// Arrange
87+
var expected = @"{
88+
""schema"": {
89+
""type"": ""array"",
90+
""items"": {
91+
""type"": ""object"",
92+
""properties"": {
93+
""id"": {
94+
""type"": ""string""
95+
}
96+
}
97+
}
98+
},
99+
""examples"": {
100+
""Success response - no results"": {
101+
""value"": [ ]
102+
}
103+
}
104+
}
105+
";
106+
MapNode node;
107+
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "examplesWithEmptyArray.json")))
108+
{
109+
node = TestHelper.CreateYamlMapNode(stream);
110+
}
111+
112+
// Act
113+
var mediaType = OpenApiV3Deserializer.LoadMediaType(node);
114+
var serialized = mediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
115+
116+
// Assert
117+
serialized.MakeLineBreaksEnvironmentNeutral()
118+
.Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
119+
}
80120
}
81121
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"schema": {
3+
"type": "array",
4+
"items": {
5+
"type": "object",
6+
"properties": {
7+
"id": {
8+
"type": "string"
9+
}
10+
}
11+
}
12+
},
13+
"examples": {
14+
"Success response - no results": {
15+
"value": []
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)