Skip to content

Commit d31ed4c

Browse files
committed
fix: path item reference annoations parsing
Signed-off-by: Vincent Biret <[email protected]>
1 parent b1578f3 commit d31ed4c

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public static IOpenApiPathItem LoadPathItem(ParseNode node, OpenApiDocument host
5555
if (pointer != null)
5656
{
5757
var reference = GetReferenceIdAndExternalResource(pointer);
58-
return new OpenApiPathItemReference(reference.Item1, hostDocument, reference.Item2);
58+
var pathItemReference = new OpenApiPathItemReference(reference.Item1, hostDocument, reference.Item2);
59+
pathItemReference.Reference.SetMetadataFromMapNode(mapNode);
60+
return pathItemReference;
5961
}
6062

6163
var pathItem = new OpenApiPathItem();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Text.Json.Nodes;
2+
using Microsoft.OpenApi.Reader;
3+
using Microsoft.OpenApi.Reader.V31;
4+
using Xunit;
5+
6+
namespace Microsoft.OpenApi.Readers.Tests.V31Tests;
7+
8+
public class OpenApiPathItemReferenceDeserializerTests
9+
{
10+
[Fact]
11+
public void ShouldDeserializePathItemReferenceAnnotations()
12+
{
13+
var json =
14+
"""
15+
{
16+
"$ref": "#/components/pathItems/MyPathItem",
17+
"description": "This is a path item reference",
18+
"summary": "PathItem Summary reference"
19+
}
20+
""";
21+
22+
var hostDocument = new OpenApiDocument();
23+
hostDocument.AddComponent("MyPathItem", new OpenApiPathItem
24+
{
25+
Summary = "This is a path item",
26+
Description = "This is a path item description",
27+
});
28+
var jsonNode = JsonNode.Parse(json);
29+
var parseNode = ParseNode.Create(new ParsingContext(new()), jsonNode);
30+
31+
var result = OpenApiV31Deserializer.LoadPathItem(parseNode, hostDocument);
32+
33+
Assert.NotNull(result);
34+
var resultReference = Assert.IsType<OpenApiPathItemReference>(result);
35+
36+
Assert.Equal("MyPathItem", resultReference.Reference.Id);
37+
Assert.Equal("This is a path item reference", resultReference.Description);
38+
Assert.Equal("PathItem Summary reference", resultReference.Summary);
39+
Assert.NotNull(resultReference.Target);
40+
}
41+
}

0 commit comments

Comments
 (0)