Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Fixes query option params with url encoded values. #1647

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CodeSnippetsReflection.OpenAPI.Test/GraphCliGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,19 @@ public async Task GeneratesSnippetsWithFilterQueryOptions()
// Then
Assert.Equal("mgc identity-governance access-reviews definitions list --filter \"contains(scope/microsoft.graph.accessReviewQueryScope/query, './members')\"", result);
}

[Fact]
public async Task GeneratesSnippetsForHttpSnippetsWithUrlEncodedValuesForSystemQueryOptionParameters()
{
// Given
string url = $"{ServiceRootUrl}/teams/XXXXXXX/members?$filter=%28microsoft.graph.aadUserConversationMember%2FdisplayName%2520eq%2520%27Harry%2520Johnson%27%2520or%2520microsoft.graph.aadUserConversationMember%2Femail%2520eq%2520%27admin%40M365x987948.OnMicrosoft.com%27%29";
using var requestPayload = new HttpRequestMessage(HttpMethod.Get, url);
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata());

// When
var result = _generator.GenerateCodeSnippet(snippetModel);

// Then
Assert.Equal("mgc teams members list --team-id {team-id} --filter \"(microsoft.graph.aadUserConversationMember/displayName eq 'Harry Johnson' or microsoft.graph.aadUserConversationMember/email eq 'admin@M365x987948.OnMicrosoft.com')\"", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Web;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;

Expand Down Expand Up @@ -225,9 +226,10 @@ private static IDictionary<string, string> ProcessQueryParameters([NotNull] in S
{
string pattern = "\\?\\$\\w*=";
string[] splittedQueryString = Regex.Split(snippetModel.QueryString, pattern, RegexOptions.Compiled, TimeSpan.FromSeconds(5));
string queryOptionFunction = HttpUtility.UrlDecode(splittedQueryString[1]);
var match = Regex.Match(snippetModel.QueryString, pattern, RegexOptions.Compiled, TimeSpan.FromSeconds(5));
string queryOption = match.Groups[0].Value.Replace("?", string.Empty, StringComparison.OrdinalIgnoreCase).Replace("=", string.Empty, StringComparison.OrdinalIgnoreCase);
string queryOptionFunction = splittedQueryString[1].Replace("$", "`$", StringComparison.OrdinalIgnoreCase);
queryOptionFunction = queryOptionFunction.Replace("$", "`$", StringComparison.OrdinalIgnoreCase);
queryOptionFunction = queryOptionFunction.Replace(queryOptionFunction, "\"" + queryOptionFunction + "\"", StringComparison.Ordinal);
splitQueryString.Add(queryOption, queryOptionFunction);
}
Expand Down