Skip to content

Commit 18d99e6

Browse files
committed
Add tests
1 parent e85dfd0 commit 18d99e6

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using FluentAssertions;
1111
using Microsoft.OpenApi.Any;
1212
using Microsoft.OpenApi.Exceptions;
13+
using Microsoft.OpenApi.Extensions;
1314
using Microsoft.OpenApi.Interfaces;
1415
using Microsoft.OpenApi.Models;
1516
using Microsoft.OpenApi.Readers.Interface;
@@ -1432,5 +1433,65 @@ public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail()
14321433

14331434
diagnostic.Errors.Should().NotBeEmpty();
14341435
}
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+
}
14351496
}
14361497
}

0 commit comments

Comments
 (0)