From e036750dc7dadc77019e3e5c59583d727f91a20a Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 18 Dec 2023 15:06:29 -0500 Subject: [PATCH 1/2] - fixes a bug where paths with multiple parameters would be considered conflicting Signed-off-by: Vincent Biret --- .../Validations/Rules/OpenApiPathsRules.cs | 2 +- .../Validations/OpenApiPathsValidationTests.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs index c25ca8aff..d94f7a31a 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiPathsRules.cs @@ -36,7 +36,7 @@ public static class OpenApiPathsRules } }); - private static readonly Regex regexPath = new Regex("\\{([^/]+)\\}", RegexOptions.Compiled, TimeSpan.FromMilliseconds(100)); + private static readonly Regex regexPath = new Regex("\\{([^/}]+)\\}", RegexOptions.Compiled, TimeSpan.FromMilliseconds(100)); /// /// A relative path to an individual endpoint. The field name MUST begin with a slash. /// diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs index 23a0a3e0f..9d3e3bb59 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs @@ -45,5 +45,22 @@ public void ValidatePathsAreUnique() errors.Should().NotBeEmpty(); errors.Select(e => e.Message).Should().BeEquivalentTo(error); } + [Fact] + public void ValidatePathsAreUniqueDoesNotConsiderMultiParametersAsIdentical() + { + // Arrange + var paths = new OpenApiPaths + { + {"/drives/{drive-id}/items/{driveItem-id}/workbook/worksheets/{workbookWorksheet-id}/charts/{workbookChart-id}/image(width={width},height={height},fittingMode='{fittingMode}')",new OpenApiPathItem() }, + {"/drives/{drive-id}/items/{driveItem-id}/workbook/worksheets/{workbookWorksheet-id}/charts/{workbookChart-id}/image(width={width},height={height})",new OpenApiPathItem() }, + {"/drives/{drive-id}/items/{driveItem-id}/workbook/worksheets/{workbookWorksheet-id}/charts/{workbookChart-id}/image(width={width})", new OpenApiPathItem() }, + }; + + // Act + var errors = paths.Validate(ValidationRuleSet.GetDefaultRuleSet()); + + // Assert + errors.Should().BeEmpty(); + } } } From 670b2595b0b8f248dc2f3befb0c60587f2e290d8 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 18 Dec 2023 15:10:36 -0500 Subject: [PATCH 2/2] - adds additional test Signed-off-by: Vincent Biret --- .../Validations/OpenApiPathsValidationTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs index 9d3e3bb59..6d0282748 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiPathsValidationTests.cs @@ -62,5 +62,21 @@ public void ValidatePathsAreUniqueDoesNotConsiderMultiParametersAsIdentical() // Assert errors.Should().BeEmpty(); } + [Fact] + public void ValidatePathsAreUniqueConsidersMultiParametersAsIdentical() + { + // Arrange + var paths = new OpenApiPaths + { + {"/drives/{drive-id}/items/{driveItem-id}/workbook/worksheets/{workbookWorksheet-id}/charts/{workbookChart-id}/image(width={width},height={height})",new OpenApiPathItem() }, + {"/drives/{drive-id}/items/{driveItem-id}/workbook/worksheets/{workbookWorksheet-id}/charts/{workbookChart-id}/image(width={width},height={size})",new OpenApiPathItem() }, + }; + + // Act + var errors = paths.Validate(ValidationRuleSet.GetDefaultRuleSet()); + + // Assert + errors.Should().NotBeEmpty(); + } } }