Skip to content

Commit

Permalink
Merge pull request #4722 from microsoft/andrueastman/pluginsfix
Browse files Browse the repository at this point in the history
Fixes indexer cleanup for glob matching.
  • Loading branch information
andrueastman authored May 24, 2024
2 parents 0e195ec + aa16a1d commit 96a9bef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Glob, HashSet<OperationType>> GetFilterPatternsFromConfiguration(HashSet<string> configPatterns)
{
return configPatterns.Select(static x =>
Expand Down
18 changes: 18 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 96a9bef

Please sign in to comment.