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

Update generated SDKs #383

Merged
merged 1 commit into from
Nov 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static IHttpClientBuilder UseCommercetoolsScopedClient(this IServiceColle
ClientName = clientName,
ClientConfiguration = clientConfiguration,
TokenProvider = tokenProvider,
SerializerService =serviceProvider.GetService<IApiSerializerService>(),
HttpClient = serviceProvider.GetService<IHttpClientFactory>().CreateClient(clientName)
SerializerService = serviceProvider.GetService<IApiSerializerService>(),
HttpClient = serviceProvider.GetService<IHttpClientFactory>().CreateClient(clientName)
}.Build();
return client;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async void DefaultLogger()
Assert.StartsWith("GET https://api.europe-west1.gcp.commercetools.com/" + clientConfiguration.ProjectKey, messages.TrimEnd());
}


[Fact]
public async void CustomLogger()
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public async void CustomLogger()
var messages = logger.GetLogMessages();
Assert.Equal("GET https://api.europe-west1.gcp.commercetools.com/" + clientConfiguration.ProjectKey, messages.TrimEnd());
}

public class CustomLoggerHandler : DelegatingHandler
{
private readonly ILogger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ private void CreateMeClient()
CustomerServices.CustomerPassword));

//Create MeClient
_meClient = new ClientBuilder {
_meClient = new ClientBuilder
{
ClientName = "MeClient",
ClientConfiguration = meClientConfig,
TokenProvider = passwordTokenProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async void not_found_middleware_stream_client()
Build();

var s = new ServiceCollection();
s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = true},middlewares: new List<DelegatingMiddleware>()
s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = true }, middlewares: new List<DelegatingMiddleware>()
{
new NotFoundMiddleware()
});
Expand All @@ -36,7 +36,7 @@ public async void not_found_middleware_stream_client()

Assert.Null(category);
}

[Fact]
public async void not_found_middleware_string_client()
{
Expand All @@ -48,7 +48,7 @@ public async void not_found_middleware_string_client()
Build();

var s = new ServiceCollection();
s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = false},middlewares: new List<DelegatingMiddleware>()
s.UseCommercetoolsApi(configuration, "Client", options: new ClientOptions() { ReadResponseAsStream = false }, middlewares: new List<DelegatingMiddleware>()
{
new NotFoundMiddleware()
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using commercetools.Api.IntegrationTests;
using commercetools.Base.Client;
using commercetools.Base.Client.Middlewares;
using commercetools.Sdk.Api;
using commercetools.Sdk.Api.Extensions;
using commercetools.Sdk.ImportApi.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ public void TestClientConfigValidationBuilder()
var tokenProvider = TokenProviderFactory
.CreateClientCredentialsTokenProvider(clientConfig, null);

new ClientBuilder {
new ClientBuilder
{
ClientName = "test",
ClientConfiguration = clientConfig,
HttpClient = null,
SerializerService = serializerService,
TokenProvider = tokenProvider}.Build();
TokenProvider = tokenProvider
}.Build();
}
catch (Exception e)
{
Expand All @@ -102,7 +104,7 @@ public void TestClientConfigValidationBuilder()
Assert.NotNull(validationEx);
Assert.IsType<ValidationException>(validationEx);
}

[Fact]
public void TestClientConfigValidation()
{
Expand Down
1 change: 0 additions & 1 deletion commercetools.Sdk/commercetools.Base.Client/ApiMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;

namespace commercetools.Base.Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ClientBuilder
public ITokenProvider TokenProvider { get; set; }
public bool ReadResponseAsStream { get; set; } = true;
public ICorrelationIdProvider CorrelationIdProvider { get; set; }

[Obsolete("Set default HttpVersion in HttpClient instead")]
public Version HttpVersion { get; set; }
public IEnumerable<DelegatingMiddleware> Middlewares { get; set; } = new List<DelegatingMiddleware>();
Expand Down
21 changes: 10 additions & 11 deletions commercetools.Sdk/commercetools.Base.Client/ClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Net.Http;
using commercetools.Base.Client.Middlewares;
using commercetools.Base.Client.Tokens;
Expand All @@ -23,16 +22,16 @@ public static IClient Create(
Version httpVersion = null)
{
return new ClientBuilder()
{
ClientName = clientName,
ClientConfiguration = configuration,
HttpClient = factory.CreateClient(clientName),
SerializerService = serializerService,
TokenProvider = tokenProvider,
ReadResponseAsStream = readResponseAsStream,
CorrelationIdProvider = correlationIdProvider,
HttpVersion = httpVersion
}.Build();
{
ClientName = clientName,
ClientConfiguration = configuration,
HttpClient = factory.CreateClient(clientName),
SerializerService = serializerService,
TokenProvider = tokenProvider,
ReadResponseAsStream = readResponseAsStream,
CorrelationIdProvider = correlationIdProvider,
HttpVersion = httpVersion
}.Build();
}

[Obsolete("Use ClientBuilder.CreateMiddlewareStack instead")]
Expand Down
2 changes: 1 addition & 1 deletion commercetools.Sdk/commercetools.Base.Client/CtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IApiResponse<T>> SendAsync<T>(HttpRequestMessage requestMessag
var result = await SendAsJsonAsync(requestMessage, cancellationToken);
if (string.IsNullOrEmpty(result.Body))
{
return new ApiResponse<T>(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, default);
return new ApiResponse<T>(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, default);
}
var body = this.SerializerService.Deserialize<T>(result.Body);
return new ApiResponse<T>(result.StatusCode, result.ReasonPhrase, result.HttpHeaders, body);
Expand Down
21 changes: 10 additions & 11 deletions commercetools.Sdk/commercetools.Base.Client/DefaultHttpLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -19,7 +18,7 @@ public async Task LogRequestBody(ILogger logger, LogLevel logLevel, HttpRequestM
request.RequestUri.AbsoluteUri, RedactAuthorizationHeader(request.Headers), SecuredBody(body));
}
}

public async Task LogResponseBody(ILogger logger, LogLevel logLevel, HttpRequestMessage request, HttpResponseMessage response, long elapsed)
{
if (logger.IsEnabled(logLevel))
Expand All @@ -29,7 +28,7 @@ public async Task LogResponseBody(ILogger logger, LogLevel logLevel, HttpRequest
request.RequestUri.AbsoluteUri, (int)response.StatusCode, elapsed, RedactAuthorizationHeader(request.Headers), SecuredBody(body));
}
}

public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request)
{
if (logger.IsEnabled(logLevel))
Expand All @@ -38,7 +37,7 @@ public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request)
request.RequestUri.AbsoluteUri, RedactAuthorizationHeader(request.Headers));
}
}

public void Log(ILogger logger, LogLevel level, HttpRequestMessage request, HttpResponseMessage response, long elapsed)
{
if (logger.IsEnabled(level))
Expand All @@ -57,12 +56,12 @@ public void Log(ILogger logger, LogLevel logLevel, HttpRequestMessage request, A
}
}


private static string RedactAuthorizationHeader(HttpRequestHeaders headers)
{
var headString = from header in headers
where header.Key.ToLower() != "authorization"
select header.Key + ": " + string.Join(", ", header.Value);
where header.Key.ToLower() != "authorization"
select header.Key + ": " + string.Join(", ", header.Value);

return "[" + string.Join(", ", headString) + "]";
}
Expand All @@ -79,12 +78,12 @@ private static string GetCorrelationId(ApiHttpHeaders headers)
{
return headers.GetFirst("X-Correlation-Id") ?? "-";
}

private static string GetCorrelationId(HttpResponseHeaders headers)
{
return GetHeader(headers, "X-Correlation-ID");
}

private static string GetHeader(HttpResponseHeaders headers, string headerName)
{
var headerValue = "-";
Expand All @@ -96,12 +95,12 @@ private static string GetHeader(HttpResponseHeaders headers, string headerName)

return headerValue;
}

private static string GetServerTiming(HttpResponseHeaders headers)
{
return GetHeader(headers, "Server-Timing");
}

private static string GetServerTiming(ApiHttpHeaders headers)
{
return headers.GetFirst("Server-Timing") ?? "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ private static IDictionary<string, IHttpClientBuilder> UseMultipleClients(this I
builders.TryAdd(clientName, services.SetupClient(clientName, errorResponseTypeMapper, serializerFactory, options));
services.AddSingleton(serviceProvider =>
{

var client = new ClientBuilder {

var client = new ClientBuilder
{
ClientName = clientName,
ClientConfiguration = clientConfiguration,
HttpClient = serviceProvider.GetService<IHttpClientFactory>().CreateClient(clientName),
Expand Down Expand Up @@ -88,7 +89,8 @@ private static IDictionary<string, IHttpClientBuilder> UseSingleClient(this ISer

services.AddSingleton(serviceProvider =>
{
var client = new ClientBuilder {
var client = new ClientBuilder
{
ClientName = clientName,
ClientConfiguration = clientConfiguration,
HttpClient = serviceProvider.GetService<IHttpClientFactory>().CreateClient(clientName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace commercetools.Base.Client
public class ErrorHandler : DelegatingHandler
{
private readonly Func<HttpResponseMessage, object> _errorResponseBodyMapper;

public ErrorHandler(Func<HttpResponseMessage, object> errorResponseBodyMapper)
{
this._errorResponseBodyMapper = errorResponseBodyMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ protected override async Task<HttpResponseMessage> SendAsync(
{
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
watch.Stop();

_httpLogger.Log(logger, (int)response.StatusCode < 400 ? _loggerHandlerOptions.ResponseLogEvent : _loggerHandlerOptions.DefaultExceptionLogEvent, request, response, watch.ElapsedMilliseconds);
await _httpLogger.LogResponseBody(logger, LogLevel.Trace, request, response, watch.ElapsedMilliseconds);

return response;
}
catch (ApiHttpException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace commercetools.Base.Client.Middlewares;

public class NotFoundMiddleware: DelegatingMiddleware
public class NotFoundMiddleware : DelegatingMiddleware
{
protected internal override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Expand Down
1 change: 1 addition & 0 deletions reference.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
505b3af56b4452b22dfb595f93e010b3e2fccc53
1 change: 1 addition & 0 deletions references.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,4 @@ f254d17f05343dcc4299fc53ff9b335b5ef63d69
6892be230f1ad73f1150dd544c9fa7fee0e6b123
6a8624fb41168a6a78ac836b7208c2790a686608
b747e1fa4f246b748a89bccbfd8a43f5b6f51175
f4cb4be0d9a27d8799b209eeb70db38bd80d5f57
Loading