-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiOperationDeserializer.cs
More file actions
118 lines (111 loc) · 3.95 KB
/
OpenApiOperationDeserializer.cs
File metadata and controls
118 lines (111 loc) · 3.95 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Reader.ParseNodes;
namespace Microsoft.OpenApi.Reader.V31
{
/// <summary>
/// Class containing logic to deserialize Open API V31 document into
/// runtime Open API object model.
/// </summary>
internal static partial class OpenApiV31Deserializer
{
private static readonly FixedFieldMap<OpenApiOperation> _operationFixedFields =
new()
{
{
"tags", (o, n, doc) => {
if (n.CreateSimpleList((valueNode, doc) => LoadTagByReference(valueNode.GetScalarValue(), doc), doc) is {Count: > 0} tags)
{
o.Tags = new HashSet<OpenApiTagReference>(tags, OpenApiTagComparer.Instance);
}
}
},
{
"summary", (o, n, _) =>
{
o.Summary = n.GetScalarValue();
}
},
{
"description", (o, n, _) =>
{
o.Description = n.GetScalarValue();
}
},
{
"externalDocs", (o, n, t) =>
{
o.ExternalDocs = LoadExternalDocs(n, t);
}
},
{
"operationId", (o, n, _) =>
{
o.OperationId = n.GetScalarValue();
}
},
{
"parameters", (o, n, t) =>
{
o.Parameters = n.CreateList(LoadParameter, t);
}
},
{
"requestBody", (o, n, t) =>
{
o.RequestBody = LoadRequestBody(n, t);
}
},
{
"responses", (o, n, t) =>
{
o.Responses = LoadResponses(n, t);
}
},
{
"callbacks", (o, n, t) =>
{
o.Callbacks = n.CreateMap(LoadCallback, t);
}
},
{
"deprecated", (o, n, _) =>
{
o.Deprecated = bool.Parse(n.GetScalarValue());
}
},
{
"security", (o, n, t) =>
{
o.Security = n.CreateList(LoadSecurityRequirement, t);
}
},
{
"servers", (o, n, t) =>
{
o.Servers = n.CreateList(LoadServer, t);
}
},
};
private static readonly PatternFieldMap<OpenApiOperation> _operationPatternFields =
new()
{
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p,n))},
};
internal static OpenApiOperation LoadOperation(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode("Operation");
var operation = new OpenApiOperation();
ParseMap(mapNode, operation, _operationFixedFields, _operationPatternFields, hostDocument);
return operation;
}
private static OpenApiTagReference LoadTagByReference(string tagName, OpenApiDocument hostDocument)
{
var tagObject = new OpenApiTagReference(tagName, hostDocument);
return tagObject;
}
}
}