diff --git a/CHANGELOG.md b/CHANGELOG.md index 08dd3c5055..0985b86ce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixes a bug where models would be duplicated in some allOf scenarios [#4191](https://github.com/microsoft/kiota/issues/4191) - Fixes a bug where CLI Generation does not handle path parameters of type "string" and format "date", "date-time", "time", etc. [#4615](https://github.com/microsoft/kiota/issues/4615) - Fixes a bug where request executors would be missing Untyped parameters in dotnet [#4692](https://github.com/microsoft/kiota/issues/4692) +- Fixes a bug where indexers in include/exclude patters were not normalized if the indexer was the last segment without a slash at the end [#4715](https://github.com/microsoft/kiota/issues/4715) - Fixes a bug where CLI generation doesnot handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707) ## [1.14.0] - 2024-05-02 diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 9310c3c5c0..bb39714bf3 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -331,9 +331,9 @@ private async Task FinalizeWorkspaceAsync(Stopwatch sw, int stepId, OpenApiUrlTr } private readonly WorkspaceManagementService workspaceManagementService; private static readonly GlobComparer globComparer = new(); - [GeneratedRegex(@"([\/\\])\{[\w\d-]+\}([\/\\])", RegexOptions.IgnoreCase | RegexOptions.Singleline, 2000)] + [GeneratedRegex(@"([\/\\])\{[\w\d-]+\}([\/\\])?", RegexOptions.IgnoreCase | RegexOptions.Singleline, 2000)] private static partial Regex MultiIndexSameLevelCleanupRegex(); - private static string ReplaceAllIndexesWithWildcard(string path, uint depth = 10) => depth == 0 ? path : ReplaceAllIndexesWithWildcard(MultiIndexSameLevelCleanupRegex().Replace(path, "$1{*}$2"), depth - 1); // the bound needs to be greedy to avoid replacing anything else than single path parameters + internal static string ReplaceAllIndexesWithWildcard(string path, uint depth = 10) => depth == 0 ? path : ReplaceAllIndexesWithWildcard(MultiIndexSameLevelCleanupRegex().Replace(path, "$1{*}$2"), depth - 1); // the bound needs to be greedy to avoid replacing anything else than single path parameters private static Dictionary> GetFilterPatternsFromConfiguration(HashSet configPatterns) { return configPatterns.Select(static x => diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 1229f61547..7240e27a4f 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -8647,6 +8647,24 @@ public void CleansUpOperationIdAddsMissingOperationId() Assert.Equal("directory_administrativeunits_post", operations[1].Value.OperationId); } + [Theory] + [InlineData("repos/{id}/", "repos/{*}/")] // normalish case + [InlineData("repos/{id}", "repos/{*}")]// no trailing slash + [InlineData("/repos/{id}", "/repos/{*}")]// no trailing slash(slash at begining). + [InlineData("repos/{id}/dependencies/{dep-id}", "repos/{*}/dependencies/{*}")]// multiple indexers + [InlineData("/repos/{id}/dependencies/{dep-id}/", "/repos/{*}/dependencies/{*}/")]// multiple indexers(slash at begining and end). + [InlineData("/repos/{id}/dependencies/{dep-id}", "/repos/{*}/dependencies/{*}")]// multiple indexers(slash at begining). + [InlineData("repos/{id}/{dep-id}", "repos/{*}/{*}")]// indexers following each other. + [InlineData("/repos/{id}/{dep-id}", "/repos/{*}/{*}")]// indexers following each other(slash at begining). + [InlineData("repos/msft", "repos/msft")]// no indexers + [InlineData("/repos", "/repos")]// no indexers(slash at begining). + [InlineData("repos", "repos")]// no indexers + public void ReplacesAllIndexesWithWildcard(string inputPath, string expectedGlob) + { + var resultGlob = KiotaBuilder.ReplaceAllIndexesWithWildcard(inputPath); + Assert.Equal(expectedGlob, resultGlob); + } + [Fact] public void CleansUpOperationIdChangesOperationId() {