-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiXmlDeserializer.cs
More file actions
70 lines (64 loc) · 2.27 KB
/
OpenApiXmlDeserializer.cs
File metadata and controls
70 lines (64 loc) · 2.27 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
namespace Microsoft.OpenApi.Reader.V2
{
/// <summary>
/// Class containing logic to deserialize Open API V3 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV2Deserializer
{
private static readonly FixedFieldMap<OpenApiXml> _xmlFixedFields = new()
{
{
"name",
(o, n, _) => o.Name = n.GetScalarValue()
},
{
"namespace", (o, n, _) =>
{
if (Uri.IsWellFormedUriString(n.GetScalarValue(), UriKind.Absolute))
{
o.Namespace = new(n.GetScalarValue(), UriKind.Absolute);
}
else
{
throw new OpenApiReaderException($"Xml Namespace requires absolute URL. '{n.GetScalarValue()}' is not valid.");
}
}
},
{
"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()
{
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiXml LoadXml(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode("xml");
var xml = new OpenApiXml();
foreach (var property in mapNode)
{
property.ParseField(xml, _xmlFixedFields, _xmlPatternFields, hostDocument);
}
return xml;
}
}
}