-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAsyncApiParameterDeserializer.cs
More file actions
61 lines (51 loc) · 2.12 KB
/
AsyncApiParameterDeserializer.cs
File metadata and controls
61 lines (51 loc) · 2.12 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
namespace ByteBard.AsyncAPI.Readers
{
using ByteBard.AsyncAPI.Extensions;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using System.Linq;
internal static partial class AsyncApiV3Deserializer
{
private static FixedFieldMap<AsyncApiParameter> parameterFixedFields = new()
{
{ "enum", (a, n) => { a.Enum = n.CreateSimpleList(n2 => n2.GetScalarValue()); } },
{ "default", (a, n) => { a.Default = n.GetScalarValue(); } },
{ "description", (a, n) => { a.Description = n.GetScalarValue(); } },
{ "examples", (a, n) => { a.Examples = n.CreateSimpleList(n2 => n2.GetScalarValue()); } },
{ "location", (a, n) => { a.Location = n.GetScalarValue(); } },
};
private static PatternFieldMap<AsyncApiParameter> parameterPatternFields =
new()
{
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
};
private static void LoadParameterFromSchema(AsyncApiParameter instance, ParseNode node)
{
var schema = AsyncApiJsonSchemaDeserializer.LoadSchema(node);
if (schema.Enum.Any())
{
instance.Enum = schema.Enum.Select(e => e.GetValue<string>()).ToList();
}
if (schema.Default != null)
{
instance.Default = schema.Default.GetValue<string>();
}
if (schema.Examples.Any())
{
instance.Examples = schema.Examples.Select(e => e.GetValue<string>()).ToList();
}
}
public static AsyncApiParameter LoadParameter(ParseNode node)
{
var mapNode = node.CheckMapNode("parameter");
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
return new AsyncApiParameterReference(pointer);
}
var parameter = new AsyncApiParameter();
ParseMap(mapNode, parameter, parameterFixedFields, parameterPatternFields);
return parameter;
}
}
}