diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs index 8e3a6c864..266809561 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs @@ -4,9 +4,11 @@ using System.IO; using FluentAssertions; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.ParseNodes; using Microsoft.OpenApi.Readers.V3; +using Microsoft.OpenApi.Tests; using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V3Tests @@ -77,5 +79,43 @@ public void ParseMediaTypeWithExamplesShouldSucceed() } }); } + + [Fact] + public void ParseMediaTypeWithEmptyArrayInExamplesWorks() + { + // Arrange + var expected = @"{ + ""schema"": { + ""type"": ""array"", + ""items"": { + ""type"": ""object"", + ""properties"": { + ""id"": { + ""type"": ""string"" + } + } + } + }, + ""examples"": { + ""Success response - no results"": { + ""value"": [ ] + } + } +} +"; + MapNode node; + using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "examplesWithEmptyArray.json"))) + { + node = TestHelper.CreateYamlMapNode(stream); + } + + // Act + var mediaType = OpenApiV3Deserializer.LoadMediaType(node); + var serialized = mediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + + // Assert + serialized.MakeLineBreaksEnvironmentNeutral() + .Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral()); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiMediaType/examplesWithEmptyArray.json b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiMediaType/examplesWithEmptyArray.json new file mode 100644 index 000000000..0d13dcaf2 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiMediaType/examplesWithEmptyArray.json @@ -0,0 +1,18 @@ +{ + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + } + }, + "examples": { + "Success response - no results": { + "value": [] + } + } +} \ No newline at end of file