Skip to content

Commit 8ed4512

Browse files
committed
chore: adds unit tests for tags reference parsing
Signed-off-by: Vincent Biret <[email protected]>
1 parent ccc3733 commit 8ed4512

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text.Json.Nodes;
4+
using Microsoft.OpenApi.Reader;
5+
using Microsoft.OpenApi.Reader.V31;
6+
using Xunit;
7+
8+
namespace Microsoft.OpenApi.Readers.Tests.V31Tests;
9+
10+
public class OpenApiTagReferenceDeserializerTests
11+
{
12+
[Fact]
13+
public void ShouldDeserializeTagReferenceAnnotations()
14+
{
15+
var json =
16+
"""
17+
{
18+
"tags" : [
19+
"MyTag"
20+
]
21+
}
22+
""";
23+
24+
var hostDocument = new OpenApiDocument();
25+
hostDocument.Tags ??= new HashSet<OpenApiTag>();
26+
hostDocument.Tags.Add(new OpenApiTag
27+
{
28+
Name = "MyTag",
29+
Description = "This is a tag description",
30+
});
31+
var jsonNode = JsonNode.Parse(json);
32+
var parseNode = ParseNode.Create(new ParsingContext(new()), jsonNode);
33+
34+
var result = OpenApiV31Deserializer.LoadOperation(parseNode, hostDocument);
35+
// this diverges from the other unit tests because Tag References are implemented
36+
// through the reference infrastructure for convenience, but the behave quite differently
37+
38+
Assert.NotNull(result);
39+
Assert.NotNull(result.Tags);
40+
Assert.Single(result.Tags);
41+
var resultReference = Assert.IsType<OpenApiTagReference>(result.Tags.First());
42+
43+
Assert.Equal("MyTag", resultReference.Reference.Id);
44+
Assert.Equal("This is a tag description", resultReference.Description);
45+
Assert.NotNull(resultReference.Target);
46+
}
47+
}

0 commit comments

Comments
 (0)