-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiPathItemDeserializer.cs
More file actions
81 lines (70 loc) · 3.2 KB
/
OpenApiPathItemDeserializer.cs
File metadata and controls
81 lines (70 loc) · 3.2 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Linq;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
namespace Microsoft.OpenApi.Readers.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<OpenApiPathItem> _pathItemFixedFields = new FixedFieldMap<OpenApiPathItem>
{
{
"$ref", (o,n) => {
o.Reference = new OpenApiReference() { ExternalResource = n.GetScalarValue() };
o.UnresolvedReference =true;
}
},
{
"summary", (o, n) =>
{
o.Summary = n.GetScalarValue();
}
},
{
"description", (o, n) =>
{
o.Description = n.GetScalarValue();
}
},
{"get", (o, n) => o.AddOperation(OperationType.Get, LoadOperation(n))},
{"put", (o, n) => o.AddOperation(OperationType.Put, LoadOperation(n))},
{"post", (o, n) => o.AddOperation(OperationType.Post, LoadOperation(n))},
{"delete", (o, n) => o.AddOperation(OperationType.Delete, LoadOperation(n))},
{"options", (o, n) => o.AddOperation(OperationType.Options, LoadOperation(n))},
{"head", (o, n) => o.AddOperation(OperationType.Head, LoadOperation(n))},
{"patch", (o, n) => o.AddOperation(OperationType.Patch, LoadOperation(n))},
{"trace", (o, n) => o.AddOperation(OperationType.Trace, LoadOperation(n))},
{"servers", (o, n) => o.Servers = n.CreateList(LoadServer)},
{"parameters", (o, n) => o.Parameters = n.CreateList(LoadParameter)}
};
private static readonly PatternFieldMap<OpenApiPathItem> _pathItemPatternFields =
new PatternFieldMap<OpenApiPathItem>
{
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}
};
public static OpenApiPathItem LoadPathItem(ParseNode node)
{
var mapNode = node.CheckMapNode("PathItem");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
var description = node.Context.VersionService.GetReferenceScalarValues(mapNode, OpenApiConstants.Description);
var summary = node.Context.VersionService.GetReferenceScalarValues(mapNode, OpenApiConstants.Summary);
return new OpenApiPathItem()
{
UnresolvedReference = true,
Reference = node.Context.VersionService.ConvertToOpenApiReference(pointer, ReferenceType.PathItem, summary, description)
};
}
var pathItem = new OpenApiPathItem();
ParseMap(mapNode, pathItem, _pathItemFixedFields, _pathItemPatternFields);
return pathItem;
}
}
}