-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #474 from fabich/feature/add-path-signature-unique…
…-validation [472] Add path signature unique validator
- Loading branch information
Showing
7 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Microsoft.OpenApi.Extensions; | ||
using Microsoft.OpenApi.Models; | ||
using Microsoft.OpenApi.Properties; | ||
using Xunit; | ||
|
||
namespace Microsoft.OpenApi.Validations.Tests | ||
{ | ||
public class OpenApiPathsValidationTests | ||
{ | ||
[Fact] | ||
public void ValidatePathsMustBeginWithSlash() | ||
{ | ||
// Arrange | ||
var error = string.Format(SRResource.Validation_PathItemMustBeginWithSlash, "pets/{petId}"); | ||
var paths = new OpenApiPaths | ||
{ | ||
{"pets/{petId}",new OpenApiPathItem() } | ||
}; | ||
|
||
// Act | ||
var errors = paths.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
errors.Should().NotBeEmpty(); | ||
errors.Select(e => e.Message).Should().BeEquivalentTo(error); | ||
} | ||
|
||
[Fact] | ||
public void ValidatePathsAreUnique() | ||
{ | ||
// Arrange | ||
var error = string.Format(SRResource.Validation_PathSignatureMustBeUnique, "/pets/{}"); | ||
var paths = new OpenApiPaths | ||
{ | ||
{"/pets/{petId}",new OpenApiPathItem() }, | ||
{"/pets/{name}",new OpenApiPathItem() } | ||
}; | ||
|
||
// Act | ||
var errors = paths.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
errors.Should().NotBeEmpty(); | ||
errors.Select(e => e.Message).Should().BeEquivalentTo(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters