Skip to content

Commit e9f4ba5

Browse files
Merge pull request #1819 from microsoft/mk/revert-empty-security-array-fix
Revert: Security array initialization to avoid a breaking change
2 parents 8daa326 + 7c7c25e commit e9f4ba5

File tree

3 files changed

+2
-62
lines changed

3 files changed

+2
-62
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenAp
4848
/// <summary>
4949
/// A declaration of which security mechanisms can be used across the API.
5050
/// </summary>
51-
public IList<OpenApiSecurityRequirement> SecurityRequirements { get; set; }
51+
public IList<OpenApiSecurityRequirement> SecurityRequirements { get; set; } = new List<OpenApiSecurityRequirement>();
5252

5353
/// <summary>
5454
/// A list of tags used by the specification with additional metadata.

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IOpenA
9191
/// This definition overrides any declared top-level security.
9292
/// To remove a top-level security declaration, an empty array can be used.
9393
/// </summary>
94-
public IList<OpenApiSecurityRequirement> Security { get; set; }
94+
public IList<OpenApiSecurityRequirement> Security { get; set; } = new List<OpenApiSecurityRequirement>();
9595

9696
/// <summary>
9797
/// An alternative server array to service this operation.

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

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,65 +1433,5 @@ public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail()
14331433

14341434
diagnostic.Errors.Should().NotBeEmpty();
14351435
}
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-
}
14961436
}
14971437
}

0 commit comments

Comments
 (0)