-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiCallbackDeserializer.cs
More file actions
46 lines (37 loc) · 1.64 KB
/
OpenApiCallbackDeserializer.cs
File metadata and controls
46 lines (37 loc) · 1.64 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.OpenApi.Expressions;
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<OpenApiCallback> _callbackFixedFields = new();
private static readonly PatternFieldMap<OpenApiCallback> _callbackPatternFields =
new()
{
{s => !s.StartsWith("x-"), (o, p, n, t) => o.AddPathItem(RuntimeExpression.Build(p), LoadPathItem(n, t))},
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))},
};
public static OpenApiCallback LoadCallback(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode("callback");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
var reference = GetReferenceIdAndExternalResource(pointer);
return new OpenApiCallbackReference(reference.Item1, hostDocument, reference.Item2);
}
var domainObject = new OpenApiCallback();
ParseMap(mapNode, domainObject, _callbackFixedFields, _callbackPatternFields, hostDocument);
return domainObject;
}
}
}