Skip to content

Commit

Permalink
[csharp] Address obsolete build warnings in ApiClient (OpenAPITools#1…
Browse files Browse the repository at this point in the history
…9847)

* Stop using obsolete MaxTimeout

* Convert timeout to a timespan, rather than update the configuration object

* Use async overload of RestClientExtensions.Deserialize

* Update samples

* Fix typo

* Undo timeout change
  • Loading branch information
alec-petersen authored Oct 14, 2024
1 parent 8849156 commit b5b760a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ namespace {{packageName}}.Client
}
}
private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace {{packageName}}.Client
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -613,7 +613,7 @@ namespace {{packageName}}.Client
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -570,7 +570,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -594,7 +594,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -570,7 +570,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -594,7 +594,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -586,7 +586,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -610,7 +610,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -586,7 +586,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -610,7 +610,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -586,7 +586,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -610,7 +610,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -569,7 +569,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -593,7 +593,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -585,7 +585,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -609,7 +609,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -585,7 +585,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -609,7 +609,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<Rest
}
}

private RestResponse<T> DeserializeRestResponseFromPolicy<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult)
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
if (policyResult.Outcome == OutcomeType.Successful)
{
return client.Deserialize<T>(policyResult.Result);
return await client.Deserialize<T>(policyResult.Result, cancellationToken);
}
else
{
Expand Down Expand Up @@ -569,7 +569,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.RetryPolicy;
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
return Task.FromResult(DeserializeRestResponseFromPolicy<T>(client, request, policyResult));
return DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult);
}
else
{
Expand All @@ -593,7 +593,7 @@ private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IRea
{
var policy = RetryConfiguration.AsyncRetryPolicy;
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
return DeserializeRestResponseFromPolicy<T>(client, request, policyResult);
return await DeserializeRestResponseFromPolicyAsync<T>(client, request, policyResult, cancellationToken);
}
else
{
Expand Down
Loading

0 comments on commit b5b760a

Please sign in to comment.