-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAsyncApiMessageTraitDeserializer.cs
More file actions
47 lines (41 loc) · 2.08 KB
/
AsyncApiMessageTraitDeserializer.cs
File metadata and controls
47 lines (41 loc) · 2.08 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
namespace ByteBard.AsyncAPI.Readers
{
using ByteBard.AsyncAPI.Extensions;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers.ParseNodes;
internal static partial class AsyncApiV2Deserializer
{
private static FixedFieldMap<AsyncApiMessageTrait> messageTraitFixedFields = new()
{
{ "headers", (a, n) => { a.Headers = new AsyncApiMultiFormatSchema { Schema = AsyncApiJsonSchemaDeserializer.LoadSchema(n) }; } },
{ "correlationId", (a, n) => { a.CorrelationId = LoadCorrelationId(n); } },
{ "schemaFormat", (a, n) => { a.Headers.SchemaFormat = n.GetScalarValue(); } },
{ "contentType", (a, n) => { a.ContentType = n.GetScalarValue(); } },
{ "name", (a, n) => { a.Name = n.GetScalarValue(); } },
{ "title", (a, n) => { a.Title = n.GetScalarValue(); } },
{ "summary", (a, n) => { a.Summary = n.GetScalarValue(); } },
{ "description", (a, n) => { a.Description = n.GetScalarValue(); } },
{ "tags", (a, n) => { a.Tags = n.CreateList(LoadTag); } },
{ "externalDocs", (a, n) => { a.ExternalDocs = LoadExternalDocs(n); } },
{ "bindings", (a, n) => { a.Bindings = LoadMessageBindings(n); } },
{ "examples", (a, n) => { a.Examples = n.CreateList(LoadExample); } },
};
private static PatternFieldMap<AsyncApiMessageTrait> messageTraitPatternFields =
new()
{
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
};
public static AsyncApiMessageTrait LoadMessageTrait(ParseNode node)
{
var mapNode = node.CheckMapNode("traits");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
return new AsyncApiMessageTraitReference(pointer);
}
var messageTrait = new AsyncApiMessageTrait();
ParseMap(mapNode, messageTrait, messageTraitFixedFields, messageTraitPatternFields);
return messageTrait;
}
}
}