Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Sep 4, 2024
1 parent e85dfd0 commit 18d99e6
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.Interface;
Expand Down Expand Up @@ -1432,5 +1433,65 @@ 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();
}
}
}

0 comments on commit 18d99e6

Please sign in to comment.