-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathParseNode.cs
More file actions
94 lines (76 loc) · 3.14 KB
/
ParseNode.cs
File metadata and controls
94 lines (76 loc) · 3.14 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.Reader.ParseNodes
{
internal abstract class ParseNode
{
protected ParseNode(ParsingContext parsingContext, JsonNode jsonNode)
{
Context = parsingContext;
JsonNode = jsonNode;
}
public ParsingContext Context { get; }
public JsonNode JsonNode { get; }
public MapNode CheckMapNode(string nodeName)
{
if (this is not MapNode mapNode)
{
throw new OpenApiReaderException($"{nodeName} must be a map/object", Context);
}
return mapNode;
}
public static ParseNode Create(ParsingContext context, JsonNode node)
{
if (node is JsonArray listNode)
{
return new ListNode(context, listNode);
}
if (node is JsonObject mapNode)
{
return new MapNode(context, mapNode);
}
return new ValueNode(context, node as JsonValue);
}
public virtual List<T> CreateList<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
{
throw new OpenApiReaderException("Cannot create list from this type of node.", Context);
}
public virtual Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument, T> map, OpenApiDocument hostDocument)
{
throw new OpenApiReaderException("Cannot create map from this type of node.", Context);
}
public virtual List<T> CreateSimpleList<T>(Func<ValueNode, OpenApiDocument, T> map, OpenApiDocument openApiDocument)
{
throw new OpenApiReaderException("Cannot create simple list from this type of node.", Context);
}
public virtual Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
{
throw new OpenApiReaderException("Cannot create simple map from this type of node.", Context);
}
public virtual JsonNode CreateAny()
{
throw new OpenApiReaderException("Cannot create an Any object this type of node.", Context);
}
public virtual string GetRaw()
{
throw new OpenApiReaderException("Cannot get raw value from this type of node.", Context);
}
public virtual string GetScalarValue()
{
throw new OpenApiReaderException("Cannot create a scalar value from this type of node.", Context);
}
public virtual List<JsonNode> CreateListOfAny()
{
throw new OpenApiReaderException("Cannot create a list from this type of node.", Context);
}
public virtual Dictionary<string, ISet<T>> CreateArrayMap<T>(Func<ValueNode, OpenApiDocument, T> map, OpenApiDocument openApiDocument)
{
throw new OpenApiReaderException("Cannot create array map from this type of node.", Context);
}
}
}