-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiSecuritySchemeDeserializer.cs
More file actions
94 lines (88 loc) · 3.25 KB
/
OpenApiSecuritySchemeDeserializer.cs
File metadata and controls
94 lines (88 loc) · 3.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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.Models.References;
using Microsoft.OpenApi.Reader.ParseNodes;
namespace Microsoft.OpenApi.Reader.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<OpenApiSecurityScheme> _securitySchemeFixedFields =
new()
{
{
"type",
(o, n, _) =>
{
if (!n.GetScalarValue().TryGetEnumFromDisplayName<SecuritySchemeType>(n.Context, out var type))
{
return;
}
o.Type = type;
}
},
{
"description",
(o, n, _) => o.Description = n.GetScalarValue()
},
{
"name",
(o, n, _) => o.Name = n.GetScalarValue()
},
{
"in",
(o, n, _) =>
{
if(!n.GetScalarValue().TryGetEnumFromDisplayName<ParameterLocation>(n.Context, out var _in))
{
return;
}
o.In = _in;
}
},
{
"scheme",
(o, n, _) => o.Scheme = n.GetScalarValue()
},
{
"bearerFormat",
(o, n, _) => o.BearerFormat = n.GetScalarValue()
},
{
"openIdConnectUrl",
(o, n, _) => o.OpenIdConnectUrl = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
{
"flows",
(o, n, t) => o.Flows = LoadOAuthFlows(n, t)
}
};
private static readonly PatternFieldMap<OpenApiSecurityScheme> _securitySchemePatternFields =
new()
{
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiSecurityScheme LoadSecurityScheme(ParseNode node, OpenApiDocument hostDocument = null)
{
var mapNode = node.CheckMapNode("securityScheme");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
var reference = GetReferenceIdAndExternalResource(pointer);
return new OpenApiSecuritySchemeReference(reference.Item1, hostDocument, reference.Item2);
}
var securityScheme = new OpenApiSecurityScheme();
foreach (var property in mapNode)
{
property.ParseField(securityScheme, _securitySchemeFixedFields, _securitySchemePatternFields);
}
return securityScheme;
}
}
}