-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiEncodingDeserializer.cs
More file actions
59 lines (53 loc) · 1.82 KB
/
OpenApiEncodingDeserializer.cs
File metadata and controls
59 lines (53 loc) · 1.82 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
namespace Microsoft.OpenApi.Readers.V3
{
/// <summary>
/// Class containing logic to deserialize Open API V3 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV3Deserializer
{
private static readonly FixedFieldMap<OpenApiEncoding> _encodingFixedFields = new()
{
{
"contentType",
(o, n) => o.ContentType = n.GetScalarValue()
},
{
"headers",
(o, n) => o.Headers = n.CreateMap(LoadHeader)
},
{
"style",
(o, n) => o.Style = n.GetScalarValue().GetEnumFromDisplayName<ParameterStyle>()
},
{
"explode",
(o, n) => o.Explode = bool.Parse(n.GetScalarValue())
},
{
"allowReserved",
(o, n) => o.AllowReserved = bool.Parse(n.GetScalarValue())
},
};
private static readonly PatternFieldMap<OpenApiEncoding> _encodingPatternFields =
new()
{
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiEncoding LoadEncoding(ParseNode node)
{
var mapNode = node.CheckMapNode("encoding");
var encoding = new OpenApiEncoding();
foreach (var property in mapNode)
{
property.ParseField(encoding, _encodingFixedFields, _encodingPatternFields);
}
return encoding;
}
}
}