-
Notifications
You must be signed in to change notification settings - Fork 240
/
OpenApiXmlDeserializer.cs
70 lines (64 loc) · 2.04 KB
/
OpenApiXmlDeserializer.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
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<OpenApiXml> _xmlFixedFields = new FixedFieldMap<OpenApiXml>
{
{
"name", (o, n, _) =>
{
o.Name = n.GetScalarValue();
}
},
{
"namespace", (o, n, _) =>
{
o.Namespace = new Uri(n.GetScalarValue(), UriKind.Absolute);
}
},
{
"prefix", (o, n, _) =>
{
o.Prefix = n.GetScalarValue();
}
},
{
"attribute", (o, n, _) =>
{
o.Attribute = bool.Parse(n.GetScalarValue());
}
},
{
"wrapped", (o, n, _) =>
{
o.Wrapped = bool.Parse(n.GetScalarValue());
}
},
};
private static readonly PatternFieldMap<OpenApiXml> _xmlPatternFields =
new PatternFieldMap<OpenApiXml>
{
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument = null)
{
var mapNode = node.CheckMapNode("xml");
var xml = new OpenApiXml();
foreach (var property in mapNode)
{
property.ParseField(xml, _xmlFixedFields, _xmlPatternFields);
}
return xml;
}
}
}