Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

bugfix: version range for abstractions #257

Merged
merged 4 commits into from
May 22, 2024
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
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.2] - 2024-05-21

### Added

- Added an optional parameter to kiota middleware factory so options can be configured directly. [#233](https://github.com/microsoft/kiota-http-dotnet/issues/233)
- `GetDefaultHandlerTypes` added to `KiotaClientFactory` if you're creating your own `HttpClient` and still want to use the default handlers.

### Changed

- Fixed an issue where fixed versions of abstractions would result in restore failures. [#256](https://github.com/microsoft/kiota-http-dotnet/issues/256)

## [1.4.1] - 2024-05-07

## Changed
Expand All @@ -26,20 +32,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.3.12] - 2024-04-22

- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage (https://github.com/microsoft/kiota-http-dotnet/issues/242)
- Adds `ConfigureAwait(false)` calls to async calls (https://github.com/microsoft/kiota-http-dotnet/issues/240).
- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage [#242](https://github.com/microsoft/kiota-http-dotnet/issues/242)
- Adds `ConfigureAwait(false)` calls to async calls [#240](https://github.com/microsoft/kiota-http-dotnet/issues/240).

## [1.3.11] - 2024-04-19

## Changed

- Fixes default handler for NET framework to unlock HTTP/2 scenarios (https://github.com/microsoft/kiota-http-dotnet/issues/237)
- Fixes default handler for NET framework to unlock HTTP/2 scenarios [#237](https://github.com/microsoft/kiota-http-dotnet/issues/237)

## [1.3.10] - 2024-04-19

## Changed

- Have made System.* dependencies only be included on Net Standard's TFM & net 5 (https://github.com/microsoft/kiota-http-dotnet/issues/230)
- Have made System.* dependencies only be included on Net Standard's TFM & net 5 [#230](https://github.com/microsoft/kiota-http-dotnet/issues/230)

## [1.3.9] - 2024-04-17

Expand Down Expand Up @@ -92,7 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Fixes multiple initialization of `ActivitySource` instances on each request send(https://github.com/microsoft/kiota-http-dotnet/issues/161).
- Fixes multiple initialization of `ActivitySource` instances on each request send [#161](https://github.com/microsoft/kiota-http-dotnet/issues/161).

## [1.3.0] - 2023-11-02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ public async Task SendReturnsObjectOnContent(HttpStatusCode statusCode)
var mockParseNode = new Mock<IParseNode>();
mockParseNode.Setup<IParsable>(x => x.GetObjectValue(It.IsAny<ParsableFactory<MockEntity>>()))
.Returns(new MockEntity());
var mockParseNodeFactory = new Mock<IParseNodeFactory>();
mockParseNodeFactory.Setup<IParseNode>(x => x.GetRootParseNode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(mockParseNode.Object);
var mockParseNodeFactory = new Mock<IAsyncParseNodeFactory>();
mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(mockParseNode.Object));
var adapter = new HttpClientRequestAdapter(_authenticationProvider, httpClient: client, parseNodeFactory: mockParseNodeFactory.Object);
var requestInfo = new RequestInformation
{
Expand All @@ -393,7 +393,7 @@ public async Task RetriesOnCAEResponse()
StatusCode = methodCalled ? HttpStatusCode.OK : HttpStatusCode.Unauthorized,
Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("Test")))
};
if (!methodCalled)
if(!methodCalled)
response.Headers.WwwAuthenticate.Add(new("Bearer", "realm=\"\", authorization_uri=\"https://login.microsoftonline.com/common/oauth2/authorize\", client_id=\"00000003-0000-0000-c000-000000000000\", error=\"insufficient_claims\", claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTY1MjgxMzUwOCJ9fX0=\""));
methodCalled = true;
return Task.FromResult(response);
Expand Down Expand Up @@ -440,7 +440,7 @@ public async Task SetsTheApiExceptionStatusCode(HttpStatusCode statusCode)
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo);
Assert.Fail("Expected an ApiException to be thrown");
}
catch (ApiException e)
catch(ApiException e)
{
Assert.Equal((int)statusCode, e.ResponseStatusCode);
Assert.True(e.ResponseHeaders.ContainsKey("request-id"));
Expand All @@ -467,9 +467,9 @@ public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC
var mockParseNode = new Mock<IParseNode>();
mockParseNode.Setup<IParsable>(x => x.GetObjectValue(It.IsAny<ParsableFactory<IParsable>>()))
.Returns(new MockError("A general error occured"));
var mockParseNodeFactory = new Mock<IParseNodeFactory>();
mockParseNodeFactory.Setup<IParseNode>(x => x.GetRootParseNode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(mockParseNode.Object);
var mockParseNodeFactory = new Mock<IAsyncParseNodeFactory>();
mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(mockParseNode.Object));
var adapter = new HttpClientRequestAdapter(_authenticationProvider, mockParseNodeFactory.Object, httpClient: client);
var requestInfo = new RequestInformation
{
Expand All @@ -485,7 +485,7 @@ public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping);
Assert.Fail("Expected an ApiException to be thrown");
}
catch (MockError mockError)
catch(MockError mockError)
{
Assert.Equal((int)statusCode, mockError.ResponseStatusCode);
Assert.Equal("A general error occured", mockError.Message);
Expand All @@ -511,9 +511,9 @@ public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
var mockParseNode = new Mock<IParseNode>();
mockParseNode.Setup<IParsable>(x => x.GetObjectValue(It.IsAny<ParsableFactory<IParsable>>()))
.Returns(new MockError("A general error occured: " + statusCode.ToString()));
var mockParseNodeFactory = new Mock<IParseNodeFactory>();
mockParseNodeFactory.Setup<IParseNode>(x => x.GetRootParseNode(It.IsAny<string>(), It.IsAny<Stream>()))
.Returns(mockParseNode.Object);
var mockParseNodeFactory = new Mock<IAsyncParseNodeFactory>();
mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(mockParseNode.Object));
var adapter = new HttpClientRequestAdapter(_authenticationProvider, mockParseNodeFactory.Object, httpClient: client);
var requestInfo = new RequestInformation
{
Expand All @@ -529,7 +529,7 @@ public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
var response = await adapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping);
Assert.Fail("Expected an ApiException to be thrown");
}
catch (ApiException apiException)
catch(ApiException apiException)
{
Assert.Equal((int)statusCode, apiException.ResponseStatusCode);
Assert.Contains("The server returned an unexpected status code and no error factory is registered for this code", apiException.Message);
Expand Down
9 changes: 6 additions & 3 deletions src/HttpClientRequestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
{
using var span = startTracingSpan(requestInfo, nameof(SendCollectionAsync));
var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span).ConfigureAwait(false);
requestInfo.Content?.Dispose();

Check warning on line 94 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Await DisposeAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)
var responseHandler = GetResponseHandler(requestInfo);
if(responseHandler == null)
{
Expand Down Expand Up @@ -127,7 +127,7 @@
{
using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveCollectionAsync));
var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span).ConfigureAwait(false);
requestInfo.Content?.Dispose();

Check warning on line 130 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Await DisposeAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)
var responseHandler = GetResponseHandler(requestInfo);
if(responseHandler == null)
{
Expand Down Expand Up @@ -168,7 +168,7 @@
{
using var span = startTracingSpan(requestInfo, nameof(SendAsync));
var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span).ConfigureAwait(false);
requestInfo.Content?.Dispose();

Check warning on line 171 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Await DisposeAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)
var responseHandler = GetResponseHandler(requestInfo);
if(responseHandler == null)
{
Expand Down Expand Up @@ -204,7 +204,7 @@
/// <param name="errorMapping">The error factories mapping to use in case of a failed request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use for cancelling the request.</param>
/// <returns>The deserialized primitive response model.</returns>
public async Task<ModelType?> SendPrimitiveAsync<ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default)

Check warning on line 207 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 207 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveAsync));
var modelType = typeof(ModelType);
Expand Down Expand Up @@ -324,7 +324,7 @@
{
using var span = startTracingSpan(requestInfo, nameof(SendNoContentAsync));
var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span).ConfigureAwait(false);
requestInfo.Content?.Dispose();

Check warning on line 327 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Await DisposeAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)
var responseHandler = GetResponseHandler(requestInfo);
if(responseHandler == null)
{
Expand All @@ -350,7 +350,7 @@
activity?.SetTag("com.microsoft.kiota.response.type", result.GetType().FullName);
}
}
private static async Task DrainAsync(HttpResponseMessage response, CancellationToken cancellationToken)

Check warning on line 353 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unused method parameter 'cancellationToken'. (https://rules.sonarsource.com/csharp/RSPEC-1172)
{
if(response.Content != null)
{
Expand Down Expand Up @@ -441,8 +441,11 @@
using var contentStream = await (response.Content?.ReadAsStreamAsync() ?? Task.FromResult(Stream.Null)).ConfigureAwait(false);
#endif
if(contentStream == Stream.Null || (contentStream.CanSeek && contentStream.Length == 0))
return null;// ensure a usefule stream is passed to the factory
var rootNode = pNodeFactory.GetRootParseNode(responseContentType!, contentStream);
return null;// ensure a useful stream is passed to the factory
#pragma warning disable CS0618 // Type or member is obsolete
//TODO remove with v2

Check warning on line 446 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)

Check warning on line 446 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
var rootNode = pNodeFactory is IAsyncParseNodeFactory asyncParseNodeFactory ? await asyncParseNodeFactory.GetRootParseNodeAsync(responseContentType!, contentStream, cancellationToken).ConfigureAwait(false) : pNodeFactory.GetRootParseNode(responseContentType!, contentStream);
#pragma warning restore CS0618 // Type or member is obsolete
return rootNode;
}
private const string ClaimsKey = "claims";
Expand Down Expand Up @@ -524,7 +527,7 @@
return result;
else throw new InvalidOperationException($"Could not convert the request information to a {typeof(T).Name}");
}
private HttpRequestMessage GetRequestMessageFromRequestInformation(RequestInformation requestInfo, Activity? activityForAttributes)

Check warning on line 530 in src/HttpClientRequestAdapter.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
using var span = activitySource?.StartActivity(nameof(GetRequestMessageFromRequestInformation));
SetBaseUrlForRequestInformation(requestInfo);// this method can also be called from a different context so ensure the baseUrl is added.
Expand All @@ -538,7 +541,7 @@
{
Method = new HttpMethod(requestInfo.HttpMethod.ToString().ToUpperInvariant()),
RequestUri = requestUri,
Version=new Version(2,0)
Version = new Version(2, 0)
};

if(requestInfo.RequestOptions.Any())
Expand Down
16 changes: 10 additions & 6 deletions src/Microsoft.Kiota.Http.HttpClientLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,32 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);NU5048;NETSDK1138</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">
<PropertyGroup
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net8.0'))">
<PropertyGroup
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.8.3" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="[1.9.1, 2.0.0)" />
</ItemGroup>

<!-- NET 5 target to be removed on next major version-->
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0' or '$(TargetFramework)'== 'netStandard2.0' or '$(TargetFramework)' == 'netStandard2.1' or '$(TargetFramework)' == 'net462'">
<ItemGroup
Condition="'$(TargetFramework)' == 'net5.0' or '$(TargetFramework)'== 'netStandard2.0' or '$(TargetFramework)' == 'netStandard2.1' or '$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="[6.0,9.0)" />
<PackageReference Include="System.Text.Json" Version="[6.0,9.0)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="[6.0,9.0)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
Expand All @@ -69,4 +73,4 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>
</Project>
Loading