-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiContactDeserializer.cs
More file actions
48 lines (42 loc) · 1.45 KB
/
OpenApiContactDeserializer.cs
File metadata and controls
48 lines (42 loc) · 1.45 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
// 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.V2
{
/// <summary>
/// Class containing logic to deserialize Open API V2 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV2Deserializer
{
private static readonly FixedFieldMap<OpenApiContact> _contactFixedFields = new()
{
{
"name",
(o, n, t) => o.Name = n.GetScalarValue()
},
{
"url",
(o, n, t) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
{
"email",
(o, n, t) => o.Email = n.GetScalarValue()
},
};
private static readonly PatternFieldMap<OpenApiContact> _contactPatternFields = new()
{
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
};
public static OpenApiContact LoadContact(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node as MapNode;
var contact = new OpenApiContact();
ParseMap(mapNode, contact, _contactFixedFields, _contactPatternFields);
return contact;
}
}
}