forked from ByteBardOrg/AsyncAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncApiDocumentDeserializer.cs
More file actions
37 lines (31 loc) · 1.4 KB
/
AsyncApiDocumentDeserializer.cs
File metadata and controls
37 lines (31 loc) · 1.4 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
namespace ByteBard.AsyncAPI.Readers
{
using ByteBard.AsyncAPI.Extensions;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers.ParseNodes;
internal static partial class AsyncApiV3Deserializer
{
private static FixedFieldMap<AsyncApiDocument> asyncApiFixedFields = new()
{
{ "asyncapi", (a, n) => { a.Asyncapi = "3.1.0"; } },
{ "id", (a, n) => a.Id = n.GetScalarValue() },
{ "info", (a, n) => a.Info = LoadInfo(n) },
{ "servers", (a, n) => a.Servers = n.CreateMap(LoadServer) },
{ "defaultContentType", (a, n) => a.DefaultContentType = n.GetScalarValue() },
{ "channels", (a, n) => a.Channels = n.CreateMap(LoadChannel) },
{ "operations", (a, n) => a.Operations = n.CreateMap(LoadOperation) },
{ "components", (a, n) => a.Components = LoadComponents(n) },
};
private static PatternFieldMap<AsyncApiDocument> asyncApiPatternFields = new()
{
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
};
public static AsyncApiDocument LoadAsyncApi(RootNode rootNode)
{
var document = new AsyncApiDocument();
var asyncApiNode = rootNode.GetMap();
ParseMap(asyncApiNode, document, asyncApiFixedFields, asyncApiPatternFields);
return document;
}
}
}