diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index ee760451f..120210fb0 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -33,7 +33,10 @@ - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 83bc1be2e..d33f8a942 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -3,7 +3,7 @@ netstandard2.0 latest true - 1.6.20 + 1.6.21 OpenAPI.NET Readers for JSON and YAML documents true @@ -18,8 +18,10 @@ - - all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index 0e7205ef0..5545dc84f 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -8,7 +8,10 @@ true - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 61680a879..703291eb4 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -3,7 +3,7 @@ netstandard2.0 Latest true - 1.6.20 + 1.6.21 .NET models with JSON and YAML writers for OpenAPI specification true @@ -37,8 +37,9 @@ - - all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 745bb3cdb..1a7035793 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -48,7 +48,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenAp /// /// A declaration of which security mechanisms can be used across the API. /// - public IList SecurityRequirements { get; set; } + public IList SecurityRequirements { get; set; } = new List(); /// /// A list of tags used by the specification with additional metadata. diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index e4bf5cc39..69054740e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -91,7 +91,7 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IOpenA /// This definition overrides any declared top-level security. /// To remove a top-level security declaration, an empty array can be used. /// - public IList Security { get; set; } + public IList Security { get; set; } = new List(); /// /// An alternative server array to service this operation. diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index a0bfa7c80..7ce9c0964 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -1433,65 +1433,5 @@ public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail() diagnostic.Errors.Should().NotBeEmpty(); } - - [Fact] - public void ParseDocumentWithMissingSecuritySchemeDefaultsToNull() - { - // Arrange - var input = @"openapi: 3.0.0 -info: - title: test - version: ""1.0"" -paths: - /test: - get: - description: description for test path - responses: - '200': - description: test -components: - securitySchemes: - apiKey0: - type: apiKey, - name: x-api-key, - in: header"; - - // Act && Assert - var doc = new OpenApiStringReader().Read(input, out var diagnostic); - - doc.Paths["/test"].Operations[OperationType.Get].Security.Should().BeNull(); - doc.SecurityRequirements.Should().BeNull(); - } - - [Fact] - public void ParseDocumentWithEmptySecuritySchemeDefaultsToEmptyList() - { - // Arrange - var input = @"openapi: 3.0.0 -info: - title: test - version: ""1.0"" -paths: - /test: - get: - description: description for test path - responses: - '200': - description: test - security: [] -security: -- apiKey0: [] -components: - securitySchemes: - apiKey0: - type: apiKey, - name: x-api-key, - in: header"; - - // Act && Assert - var doc = new OpenApiStringReader().Read(input, out var diagnostic); - - doc.Paths["/test"].Operations[OperationType.Get].Security.Should().BeEmpty(); - } } }