Skip to content

Commit

Permalink
Merge pull request #123 from andreaTP/switch-to-std-uritemplate
Browse files Browse the repository at this point in the history
Switch to std-uritemplate
  • Loading branch information
baywet authored Sep 21, 2023
2 parents 260ae84 + 667a6d6 commit f557db3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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
6 changes: 3 additions & 3 deletions Microsoft.Kiota.Abstractions.Tests/RequestInformationTests.cs
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);
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

0 comments on commit f557db3

Please sign in to comment.