Skip to content

Commit

Permalink
fix: issue 127 - Do not set first character of query parameter name t…
Browse files Browse the repository at this point in the history
…o lower case
  • Loading branch information
timandella committed Sep 23, 2023
1 parent f557db3 commit 2bf72b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ public void DoesNotSetEmptyCollectionQueryParameters()
Assert.False(requestInfo.QueryParameters.ContainsKey("select"));
}
[Fact]
public void DoesNotSetQueryParametersToLowerCaseFirstCharacter()
{
// Arrange as the request builders would
var requestInfo = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = "http://localhost/me{?%TenantId}"
};
Action<GetQueryParameters> q = x => x.TenantId = "Tenant1";
var qParams = new GetQueryParameters();
q.Invoke(qParams);

// Act
requestInfo.AddQueryParameters(qParams);

// Assert
Assert.Contains("TenantId", requestInfo.QueryParameters.Keys);
Assert.DoesNotContain("tenantId", requestInfo.QueryParameters.Keys);
}
[Fact]
public void SetsPathParametersOfDateTimeOffsetType()
{
// Arrange as the request builders would
Expand Down Expand Up @@ -381,5 +401,7 @@ internal class GetQueryParameters
/// <summary>Search items by search phrases</summary>
[QueryParameter("%24search")]
public string Search { get; set; }
/// <summary>Restrict to TenantId</summary>
public string TenantId { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void AddQueryParameters(object source)
x => (
Name: x.GetCustomAttributes(false)
.OfType<QueryParameterAttribute>()
.FirstOrDefault()?.TemplateName ?? x.Name.ToFirstCharacterLowerCase(),
.FirstOrDefault()?.TemplateName ?? x.Name,
Value: x.GetValue(source)
)
)
Expand Down

0 comments on commit 2bf72b7

Please sign in to comment.