Skip to content

Commit e455f52

Browse files
committed
fix: response reference annotations parsing
Signed-off-by: Vincent Biret <[email protected]>
1 parent d31ed4c commit e455f52

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument host
5050
if (pointer != null)
5151
{
5252
var reference = GetReferenceIdAndExternalResource(pointer);
53-
return new OpenApiResponseReference(reference.Item1, hostDocument, reference.Item2);
53+
var responseReference = new OpenApiResponseReference(reference.Item1, hostDocument, reference.Item2);
54+
responseReference.Reference.SetMetadataFromMapNode(mapNode);
55+
return responseReference;
5456
}
5557

5658
var response = new OpenApiResponse();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 OpenApiResponseReferenceDeserializerTests
9+
{
10+
[Fact]
11+
public void ShouldDeserializeResponseReferenceAnnotations()
12+
{
13+
var json =
14+
"""
15+
{
16+
"$ref": "#/components/responses/MyResponse",
17+
"description": "This is a response reference"
18+
}
19+
""";
20+
21+
var hostDocument = new OpenApiDocument();
22+
hostDocument.AddComponent("MyResponse", new OpenApiResponse
23+
{
24+
Description = "This is a response description",
25+
});
26+
var jsonNode = JsonNode.Parse(json);
27+
var parseNode = ParseNode.Create(new ParsingContext(new()), jsonNode);
28+
29+
var result = OpenApiV31Deserializer.LoadResponse(parseNode, hostDocument);
30+
31+
Assert.NotNull(result);
32+
var resultReference = Assert.IsType<OpenApiResponseReference>(result);
33+
34+
Assert.Equal("MyResponse", resultReference.Reference.Id);
35+
Assert.Equal("This is a response reference", resultReference.Description);
36+
Assert.NotNull(resultReference.Target);
37+
}
38+
}

0 commit comments

Comments
 (0)