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

Switch to std-uritemplate #123

Merged
merged 5 commits into from
Sep 21, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.2] - 2023-09-21

### Changed

- Switched from `Tavis.UriTemplates` to `Std.UriTemplate` for URI template parsing.

## [1.3.1] - 2023-08-08

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void SetsScalarCollectionContent()
serializationWriterMock.Verify(x => x.WriteCollectionOfPrimitiveValues(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()), Times.Once);
}
[Fact]
public void GetUriResolvesParametersCaseInsensitive()
public void GetUriResolvesParametersCaseSensitive()
{
// Arrange
var testRequest = new RequestInformation()
Expand All @@ -326,8 +326,8 @@ public void GetUriResolvesParametersCaseInsensitive()
UrlTemplate = "http://localhost/{URITemplate}/ParameterMapping?IsCaseSensitive={IsCaseSensitive}"
};
// Act
testRequest.PathParameters.Add("UriTemplate", "UriTemplate");
testRequest.QueryParameters.Add("iscasesensitive", "false");
testRequest.PathParameters.Add("URITemplate", "UriTemplate");
testRequest.QueryParameters.Add("IsCaseSensitive", false);

// Assert
Assert.Equal("http://localhost/UriTemplate/ParameterMapping?IsCaseSensitive=false", testRequest.URI.ToString());
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.3.1</VersionPrefix>
<VersionPrefix>1.3.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down Expand Up @@ -43,7 +43,7 @@
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="[6.0,8.0)" />
<PackageReference Include="Tavis.UriTemplates" Version="2.0.0" />
<PackageReference Include="Std.UriTemplate" Version="0.0.42" />
</ItemGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
Expand Down
10 changes: 5 additions & 5 deletions src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Linq;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions.Serialization;
using Tavis.UriTemplates;

namespace Microsoft.Kiota.Abstractions
{
Expand Down Expand Up @@ -49,20 +48,21 @@ public Uri URI
if(UrlTemplate?.IndexOf("{+baseurl}", StringComparison.OrdinalIgnoreCase) >= 0 && !PathParameters.ContainsKey("baseurl"))
throw new InvalidOperationException($"{nameof(PathParameters)} must contain a value for \"baseurl\" for the url to be built.");

var parsedUrlTemplate = new UriTemplate(UrlTemplate, caseInsensitiveParameterNames: true);
baywet marked this conversation as resolved.
Show resolved Hide resolved
var substitutions = new Dictionary<string, object>();
foreach(var urlTemplateParameter in PathParameters)
{
parsedUrlTemplate.SetParameter(urlTemplateParameter.Key, GetSanitizedValue(urlTemplateParameter.Value));
substitutions.Add(urlTemplateParameter.Key, GetSanitizedValue(urlTemplateParameter.Value));
}

foreach(var queryStringParameter in QueryParameters)
{
if(queryStringParameter.Value != null)
{
parsedUrlTemplate.SetParameter(queryStringParameter.Key, GetSanitizedValue(queryStringParameter.Value));
substitutions.Add(queryStringParameter.Key, GetSanitizedValue(queryStringParameter.Value));
}
}
return new Uri(parsedUrlTemplate.Resolve());

return new Uri(Std.UriTemplate.Expand(UrlTemplate, substitutions));
}
}
}
Expand Down