Skip to content

Commit

Permalink
Add unit test to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Aug 2, 2024
1 parent f63443f commit 0b63d77
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
},
"examples": {
"Success response - no results": {
"value": []
}
}
}

0 comments on commit 0b63d77

Please sign in to comment.