@@ -230,6 +230,66 @@ public void CreatePathsWithMultipleSegmentsWorks()
230
230
Assert . Equal ( "coupes" , rootNode . Children [ "cars" ] . Children [ "coupes" ] . Segment ) ;
231
231
}
232
232
233
+ [ Fact ]
234
+ public void CreatePathsWithTrailingSlashWorks ( )
235
+ {
236
+ var doc = new OpenApiDocument
237
+ {
238
+ Paths = new ( )
239
+ {
240
+ [ "/" ] = new OpenApiPathItem ( ) ,
241
+ [ "/cars" ] = new OpenApiPathItem ( ) ,
242
+ [ "/cars/" ] = new OpenApiPathItem ( ) ,
243
+ [ "/cars/coupes" ] = new OpenApiPathItem ( )
244
+ }
245
+ } ;
246
+
247
+ var label = "assets" ;
248
+ var rootNode = OpenApiUrlTreeNode . Create ( doc , label ) ;
249
+
250
+ Assert . NotNull ( rootNode ) ;
251
+ Assert . Single ( rootNode . Children ) ;
252
+ var carsNode = rootNode . Children [ "cars" ] ;
253
+ Assert . Equal ( "cars" , carsNode . Segment ) ;
254
+ Assert . Equal ( 2 , carsNode . Children . Count ) ;
255
+ var emptyNode = carsNode . Children [ "" ] ;
256
+ Assert . Empty ( emptyNode . Segment ) ;
257
+ Assert . Empty ( emptyNode . Children ) ;
258
+ var coupesNode = carsNode . Children [ "coupes" ] ;
259
+ Assert . Equal ( "coupes" , coupesNode . Segment ) ;
260
+ Assert . Empty ( coupesNode . Children ) ;
261
+ }
262
+
263
+ [ Fact ]
264
+ public void CreatePathsWithTrailingSlashWorksInverted ( )
265
+ {
266
+ var doc = new OpenApiDocument
267
+ {
268
+ Paths = new ( )
269
+ {
270
+ [ "/" ] = new OpenApiPathItem ( ) ,
271
+ [ "/cars/" ] = new OpenApiPathItem ( ) ,
272
+ [ "/cars" ] = new OpenApiPathItem ( ) , // only difference from previous test, tests that node mapping is not order specific
273
+ [ "/cars/coupes" ] = new OpenApiPathItem ( )
274
+ }
275
+ } ;
276
+
277
+ var label = "assets" ;
278
+ var rootNode = OpenApiUrlTreeNode . Create ( doc , label ) ;
279
+
280
+ Assert . NotNull ( rootNode ) ;
281
+ Assert . Single ( rootNode . Children ) ;
282
+ var carsNode = rootNode . Children [ "cars" ] ;
283
+ Assert . Equal ( "cars" , carsNode . Segment ) ;
284
+ Assert . Equal ( 2 , carsNode . Children . Count ) ;
285
+ var emptyNode = carsNode . Children [ "" ] ;
286
+ Assert . Empty ( emptyNode . Segment ) ;
287
+ Assert . Empty ( emptyNode . Children ) ;
288
+ var coupesNode = carsNode . Children [ "coupes" ] ;
289
+ Assert . Equal ( "coupes" , coupesNode . Segment ) ;
290
+ Assert . Empty ( coupesNode . Children ) ;
291
+ }
292
+
233
293
[ Fact ]
234
294
public void HasOperationsWorks ( )
235
295
{
@@ -468,16 +528,16 @@ public async Task VerifyDiagramFromSampleOpenAPIAsync()
468
528
await Verifier . Verify ( diagram ) ;
469
529
}
470
530
471
- public static TheoryData < string , string [ ] , string , string > SupportsTrailingSlashesInPathData => new TheoryData < string , string [ ] , string , string >
531
+ public static TheoryData < string , string [ ] , string > SupportsTrailingSlashesInPathData => new TheoryData < string , string [ ] , string >
472
532
{
473
533
// Path, children up to second to leaf, last expected leaf node name, expected leaf node path
474
- { "/cars/{car-id}/build/" , [ "cars" , "{car-id}" ] , @ "build\" , @"\cars\{car-id}\build\" } ,
475
- { "/cars/" , [ ] , @ "cars\" , @"\cars\" } ,
534
+ { "/cars/{car-id}/build/" , [ "cars" , "{car-id}" , "build" ] , @"\cars\{car-id}\build\" } ,
535
+ { "/cars/" , [ "cars" ] , @"\cars\" } ,
476
536
} ;
477
537
478
538
[ Theory ]
479
539
[ MemberData ( nameof ( SupportsTrailingSlashesInPathData ) ) ]
480
- public void SupportsTrailingSlashesInPath ( string path , string [ ] childrenBeforeLastNode , string expectedLeafNodeName , string expectedLeafNodePath )
540
+ public void SupportsTrailingSlashesInPath ( string path , string [ ] childrenBeforeLastNode , string expectedLeafNodePath )
481
541
{
482
542
var openApiDocument = new OpenApiDocument
483
543
{
@@ -496,7 +556,7 @@ public void SupportsTrailingSlashesInPath(string path, string[] childrenBeforeLa
496
556
secondToLeafNode = secondToLeafNode . Children [ childName ] ;
497
557
}
498
558
499
- Assert . True ( secondToLeafNode . Children . TryGetValue ( expectedLeafNodeName , out var leafNode ) ) ;
559
+ Assert . True ( secondToLeafNode . Children . TryGetValue ( string . Empty , out var leafNode ) ) ;
500
560
Assert . Equal ( expectedLeafNodePath , leafNode . Path ) ;
501
561
Assert . Empty ( leafNode . Children ) ;
502
562
}
0 commit comments