-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiEncodingDeserializer.cs
More file actions
76 lines (71 loc) · 2.4 KB
/
OpenApiEncodingDeserializer.cs
File metadata and controls
76 lines (71 loc) · 2.4 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
75
76
using System;
namespace Microsoft.OpenApi.Reader.V31
{
/// <summary>
/// Class containing logic to deserialize Open API V31 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV31Deserializer
{
private static readonly FixedFieldMap<OpenApiEncoding> _encodingFixedFields = new()
{
{
"contentType", (o, n, _) =>
{
o.ContentType = n.GetScalarValue();
}
},
{
"headers", (o, n, t) =>
{
o.Headers = n.CreateMap(LoadHeader, t);
}
},
{
"style", (o, n, _) =>
{
if(!n.GetScalarValue().TryGetEnumFromDisplayName<ParameterStyle>(n.Context, out var style))
{
return;
}
o.Style = style;
}
},
{
"explode", (o, n, _) =>
{
var explode = n.GetScalarValue();
if (explode is not null)
{
o.Explode = bool.Parse(explode);
}
}
},
{
"allowReserved", (o, n, _) =>
{
var allowReserved = n.GetScalarValue();
if (allowReserved is not null)
{
o.AllowReserved = bool.Parse(allowReserved);
}
}
},
};
private static readonly PatternFieldMap<OpenApiEncoding> _encodingPatternFields =
new()
{
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiEncoding LoadEncoding(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode("encoding");
var encoding = new OpenApiEncoding();
foreach (var property in mapNode)
{
property.ParseField(encoding, _encodingFixedFields, _encodingPatternFields, hostDocument);
}
return encoding;
}
}
}