@@ -26,12 +26,12 @@ public class OpenApiUrlTreeNode
26
26
/// <summary>
27
27
/// Dictionary of labels and Path Item objects that describe the operations available on a node.
28
28
/// </summary>
29
- public IDictionary < string , OpenApiPathItem > PathItems { get ; private set ; }
29
+ public IDictionary < string , OpenApiPathItem > PathItems { get ; } = new Dictionary < string , OpenApiPathItem > ( ) ;
30
30
31
31
/// <summary>
32
- /// A container to hold key value pairs of additional data describing a node.
32
+ /// A dictionary of key value pairs that contain information about a node.
33
33
/// </summary>
34
- public IDictionary < string , string > AdditionalData { get ; set ; }
34
+ public IDictionary < string , List < string > > AdditionalData { get ; set ; } = new Dictionary < string , List < string > > ( ) ;
35
35
36
36
/// <summary>
37
37
/// Flag indicating whether a node segment is a path parameter.
@@ -72,7 +72,7 @@ private OpenApiUrlTreeNode(string segment)
72
72
/// <returns>The root node of the created <see cref="OpenApiUrlTreeNode"/> directory structure.</returns>
73
73
public static OpenApiUrlTreeNode Create ( )
74
74
{
75
- return new OpenApiUrlTreeNode ( string . Empty ) ;
75
+ return new OpenApiUrlTreeNode ( "/" ) ;
76
76
}
77
77
78
78
/// <summary>
@@ -86,14 +86,16 @@ public static OpenApiUrlTreeNode Create(OpenApiDocument doc, string label)
86
86
Utils . CheckArgumentNull ( doc , nameof ( doc ) ) ;
87
87
Utils . CheckArgumentNullOrEmpty ( label , nameof ( label ) ) ;
88
88
89
- OpenApiUrlTreeNode root = new OpenApiUrlTreeNode ( string . Empty ) ;
89
+ OpenApiUrlTreeNode root = new OpenApiUrlTreeNode ( "/" ) ;
90
90
91
91
var paths = doc . Paths ;
92
92
if ( paths != null )
93
93
{
94
94
foreach ( var path in paths )
95
95
{
96
- root . Attach ( path . Key , path . Value , label ) ;
96
+ root . Attach ( path : path . Key ,
97
+ pathItem : path . Value ,
98
+ label : label ) ;
97
99
}
98
100
}
99
101
@@ -115,27 +117,38 @@ public void Attach(OpenApiDocument doc, string label)
115
117
{
116
118
foreach ( var path in paths )
117
119
{
118
- Attach ( path . Key , path . Value , label ) ;
120
+ Attach ( path : path . Key ,
121
+ pathItem : path . Value ,
122
+ label : label ) ;
119
123
}
120
124
}
121
125
}
122
126
123
127
/// <summary>
124
- /// Appends an OpenAPI path and the PathItems to an <see cref="OpenApiUrlTreeNode"/> node.
128
+ /// Appends a path and the PathItem to an <see cref="OpenApiUrlTreeNode"/> node.
125
129
/// </summary>
126
130
/// <param name="path">An OpenAPI path.</param>
127
131
/// <param name="pathItem">Path Item object that describes the operations available on an OpenAPI path.</param>
128
132
/// <param name="label">A name tag for labelling the <see cref="OpenApiUrlTreeNode"/> node.</param>
129
133
/// <returns>An <see cref="OpenApiUrlTreeNode"/> node describing an OpenAPI path.</returns>
130
- public OpenApiUrlTreeNode Attach ( string path , OpenApiPathItem pathItem , string label )
134
+ public OpenApiUrlTreeNode Attach ( string path ,
135
+ OpenApiPathItem pathItem ,
136
+ string label )
131
137
{
138
+ Utils . CheckArgumentNullOrEmpty ( label , nameof ( label ) ) ;
139
+
132
140
if ( path . StartsWith ( "/" ) )
133
141
{
134
142
// Remove leading slash
135
143
path = path . Substring ( 1 ) ;
136
144
}
145
+
137
146
var segments = path . Split ( '/' ) ;
138
- return Attach ( segments , pathItem , label , "" ) ;
147
+
148
+ return Attach ( segments : segments ,
149
+ pathItem : pathItem ,
150
+ label : label ,
151
+ currentPath : "" ) ;
139
152
}
140
153
141
154
/// <summary>
@@ -146,31 +159,31 @@ public OpenApiUrlTreeNode Attach(string path, OpenApiPathItem pathItem, string l
146
159
/// <param name="label">A name tag for labelling the <see cref="OpenApiUrlTreeNode"/> node.</param>
147
160
/// <param name="currentPath">The relative path of a node.</param>
148
161
/// <returns>An <see cref="OpenApiUrlTreeNode"/> node with all constituent properties assembled.</returns>
149
- private OpenApiUrlTreeNode Attach ( IEnumerable < string > segments , OpenApiPathItem pathItem , string label , string currentPath )
162
+ private OpenApiUrlTreeNode Attach ( IEnumerable < string > segments ,
163
+ OpenApiPathItem pathItem ,
164
+ string label ,
165
+ string currentPath )
150
166
{
151
- if ( PathItems . ContainsKey ( label ) )
152
- {
153
- throw new ArgumentException ( "A duplicate label already exists for this node." , nameof ( label ) ) ;
154
- }
155
-
156
167
var segment = segments . FirstOrDefault ( ) ;
157
168
if ( string . IsNullOrEmpty ( segment ) )
158
169
{
159
- PathItems = new Dictionary < string , OpenApiPathItem >
170
+ if ( PathItems . ContainsKey ( label ) )
160
171
{
161
- {
162
- label , pathItem
163
- }
164
- } ;
165
- Path = currentPath ;
172
+ throw new ArgumentException ( "A duplicate label already exists for this node." , nameof ( label ) ) ;
173
+ }
166
174
175
+ Path = currentPath ;
176
+ PathItems . Add ( label , pathItem ) ;
167
177
return this ;
168
178
}
169
179
170
180
// If the child segment has already been defined, then insert into it
171
181
if ( Children . ContainsKey ( segment ) )
172
182
{
173
- return Children [ segment ] . Attach ( segments . Skip ( 1 ) , pathItem , label , currentPath + "\\ " + segment ) ;
183
+ return Children [ segment ] . Attach ( segments : segments . Skip ( 1 ) ,
184
+ pathItem : pathItem ,
185
+ label : label ,
186
+ currentPath : currentPath + "\\ " + segment ) ;
174
187
}
175
188
else
176
189
{
@@ -180,7 +193,32 @@ private OpenApiUrlTreeNode Attach(IEnumerable<string> segments, OpenApiPathItem
180
193
} ;
181
194
182
195
Children [ segment ] = node ;
183
- return node . Attach ( segments . Skip ( 1 ) , pathItem , label , currentPath + "\\ " + segment ) ;
196
+
197
+ return node . Attach ( segments : segments . Skip ( 1 ) ,
198
+ pathItem : pathItem ,
199
+ label : label ,
200
+ currentPath : currentPath + "\\ " + segment ) ;
201
+ }
202
+ }
203
+
204
+ /// <summary>
205
+ /// Adds additional data information to the AdditionalData property of the node.
206
+ /// </summary>
207
+ /// <param name="additionalData">A dictionary of key value pairs that contain information about a node.</param>
208
+ public void AddAdditionalData ( Dictionary < string , List < string > > additionalData )
209
+ {
210
+ Utils . CheckArgumentNull ( additionalData , nameof ( additionalData ) ) ;
211
+
212
+ foreach ( var item in additionalData )
213
+ {
214
+ if ( AdditionalData . ContainsKey ( item . Key ) )
215
+ {
216
+ AdditionalData [ item . Key ] = item . Value ;
217
+ }
218
+ else
219
+ {
220
+ AdditionalData . Add ( item . Key , item . Value ) ;
221
+ }
184
222
}
185
223
}
186
224
}
0 commit comments