File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
test/Microsoft.OpenApi.Readers.Tests/V3Tests Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 10
10
using FluentAssertions ;
11
11
using Microsoft . OpenApi . Any ;
12
12
using Microsoft . OpenApi . Exceptions ;
13
+ using Microsoft . OpenApi . Extensions ;
13
14
using Microsoft . OpenApi . Interfaces ;
14
15
using Microsoft . OpenApi . Models ;
15
16
using Microsoft . OpenApi . Readers . Interface ;
@@ -1432,5 +1433,65 @@ public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail()
1432
1433
1433
1434
diagnostic . Errors . Should ( ) . NotBeEmpty ( ) ;
1434
1435
}
1436
+
1437
+ [ Fact ]
1438
+ public void ParseDocumentWithMissingSecuritySchemeDefaultsToNull ( )
1439
+ {
1440
+ // Arrange
1441
+ var input = @"openapi: 3.0.0
1442
+ info:
1443
+ title: test
1444
+ version: ""1.0""
1445
+ paths:
1446
+ /test:
1447
+ get:
1448
+ description: description for test path
1449
+ responses:
1450
+ '200':
1451
+ description: test
1452
+ components:
1453
+ securitySchemes:
1454
+ apiKey0:
1455
+ type: apiKey,
1456
+ name: x-api-key,
1457
+ in: header" ;
1458
+
1459
+ // Act && Assert
1460
+ var doc = new OpenApiStringReader ( ) . Read ( input , out var diagnostic ) ;
1461
+
1462
+ doc . Paths [ "/test" ] . Operations [ OperationType . Get ] . Security . Should ( ) . BeNull ( ) ;
1463
+ doc . SecurityRequirements . Should ( ) . BeNull ( ) ;
1464
+ }
1465
+
1466
+ [ Fact ]
1467
+ public void ParseDocumentWithEmptySecuritySchemeDefaultsToEmptyList ( )
1468
+ {
1469
+ // Arrange
1470
+ var input = @"openapi: 3.0.0
1471
+ info:
1472
+ title: test
1473
+ version: ""1.0""
1474
+ paths:
1475
+ /test:
1476
+ get:
1477
+ description: description for test path
1478
+ responses:
1479
+ '200':
1480
+ description: test
1481
+ security: []
1482
+ security:
1483
+ - apiKey0: []
1484
+ components:
1485
+ securitySchemes:
1486
+ apiKey0:
1487
+ type: apiKey,
1488
+ name: x-api-key,
1489
+ in: header" ;
1490
+
1491
+ // Act && Assert
1492
+ var doc = new OpenApiStringReader ( ) . Read ( input , out var diagnostic ) ;
1493
+
1494
+ doc . Paths [ "/test" ] . Operations [ OperationType . Get ] . Security . Should ( ) . BeEmpty ( ) ;
1495
+ }
1435
1496
}
1436
1497
}
You can’t perform that action at this time.
0 commit comments