This repository was archived by the owner on Nov 11, 2025. It is now read-only.
forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenApiResponseDeserializer.cs
More file actions
74 lines (68 loc) · 2.41 KB
/
OpenApiResponseDeserializer.cs
File metadata and controls
74 lines (68 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
namespace Microsoft.OpenApi.Reader.V31
{
/// <summary>
/// Class containing logic to deserialize Open API V3 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV31Deserializer
{
private static readonly FixedFieldMap<OpenApiResponse> _responseFixedFields = new()
{
{
"description", (o, n, _) =>
{
o.Description = n.GetScalarValue();
}
},
{
"headers", (o, n, t) =>
{
o.Headers = n.CreateMap(LoadHeader, t);
}
},
{
"content", (o, n, t) =>
{
o.Content = n.CreateMap(LoadMediaType, t);
}
},
{
"links", (o, n, t) =>
{
o.Links = n.CreateMap(LoadLink, t);
}
}
};
private static readonly PatternFieldMap<OpenApiResponse> _responsePatternFields =
new()
{
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) =>
{
if (p.Equals("x-oai-summary", StringComparison.OrdinalIgnoreCase))
{
o.Summary = n.GetScalarValue();
}
else
{
o.AddExtension(p, LoadExtension(p,n));
}
}}
};
public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode("response");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
var reference = GetReferenceIdAndExternalResource(pointer);
var responseReference = new OpenApiResponseReference(reference.Item1, hostDocument, reference.Item2);
responseReference.Reference.SetMetadataFromMapNode(mapNode);
return responseReference;
}
var response = new OpenApiResponse();
ParseMap(mapNode, response, _responseFixedFields, _responsePatternFields, hostDocument);
return response;
}
}
}