Skip to content

Commit

Permalink
Update generated SDKs (#211)
Browse files Browse the repository at this point in the history
Co-authored-by: Auto Mation <[email protected]>
Co-authored-by: Jens Schulze <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2023
1 parent dd77068 commit a617205
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ jobs:
CTP_Client__ClientSecret: ${{ secrets.CTP_CLIENT_SECRET }}
CTP_Client__ProjectKey: ${{ secrets.CTP_PROJECT_KEY }}
CTP_Client__Scope: ${{ secrets.CTP_SCOPE }}
CTP_Import__ClientId: ${{ secrets.CTP_CLIENT_ID }}
CTP_Import__ClientSecret: ${{ secrets.CTP_CLIENT_SECRET }}
CTP_Import__ProjectKey: ${{ secrets.CTP_PROJECT_KEY }}
CTP_Import__Scope: ${{ secrets.CTP_SCOPE }}
CTP_Import__ApiBaseAddress: "https://import.europe-west1.gcp.commercetools.com/"
CTP_MeClient__ClientId: ${{ secrets.CTP_MECLIENT_ID }}
CTP_MeClient__ClientSecret: ${{ secrets.CTP_MECLIENT_SECRET }}
CTP_MeClient__ProjectKey: ${{ secrets.CTP_MEPROJECT_KEY }}
Expand All @@ -116,6 +121,11 @@ jobs:
CTP_Client__ClientSecret: ${{ secrets.CTP_CLIENT_SECRET_PR }}
CTP_Client__ProjectKey: ${{ secrets.CTP_PROJECT_KEY_PR }}
CTP_Client__Scope: ${{ secrets.CTP_SCOPE_PR }}
CTP_Import__ClientId: ${{ secrets.CTP_CLIENT_ID_PR }}
CTP_Import__ClientSecret: ${{ secrets.CTP_CLIENT_SECRET_PR }}
CTP_Import__ProjectKey: ${{ secrets.CTP_PROJECT_KEY_PR }}
CTP_Import__Scope: ${{ secrets.CTP_SCOPE_PR }}
CTP_Import__ApiBaseAddress: "https://import.europe-west1.gcp.commercetools.com/"
CTP_MeClient__ClientId: ${{ secrets.CTP_MECLIENT_ID_PR }}
CTP_MeClient__ClientSecret: ${{ secrets.CTP_MECLIENT_SECRET_PR }}
CTP_MeClient__ProjectKey: ${{ secrets.CTP_MEPROJECT_KEY_PR }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Linq;
using commercetools.Api.IntegrationTests;
using commercetools.Base.Client;
using commercetools.Sdk.Api;
using commercetools.Sdk.Api.Extensions;
using commercetools.Sdk.ImportApi.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using ProjectApiRoot = commercetools.Sdk.Api.Client.ProjectApiRoot;
using ImportProjectApiRoot = commercetools.Sdk.ImportApi.Client.ProjectApiRoot;

namespace commercetools.Sdk.ImportApi.Tests
{
public class MultipleClientsTest
{
[Fact]
public async void api_and_import()
{
var configuration = new ConfigurationBuilder().
AddJsonFile("appsettings.test.Development.json", true).
AddEnvironmentVariables().
AddUserSecrets<ServiceProviderFixture>().
AddEnvironmentVariables("CTP_").
Build();

var s = new ServiceCollection();
s.UseCommercetoolsImportApi(configuration, "Import");
s.UseCommercetoolsApi(configuration, "Client");
var p = s.BuildServiceProvider();

var apiConfig = configuration.GetSection("Client").Get<ClientConfiguration>();
var importApiRoot = p.GetService<ImportProjectApiRoot>();
var apiRoot = p.GetService<ProjectApiRoot>();

Assert.Equal("Import", importApiRoot.ClientName);
Assert.Equal("Client", apiRoot.ClientName);
var project = await apiRoot.Get().ExecuteAsync().ConfigureAwait(false);

Assert.Equal(apiConfig.ProjectKey, project.Key);

var importContainers = await importApiRoot.ImportContainers().Get().ExecuteAsync().ConfigureAwait(false);
Assert.NotNull(importContainers);


}

[Fact]
public async void api_and_import_create_root()
{
var configuration = new ConfigurationBuilder().
AddJsonFile("appsettings.test.Development.json", true).
AddEnvironmentVariables().
AddUserSecrets<ServiceProviderFixture>().
AddEnvironmentVariables("CTP_").
Build();

var s = new ServiceCollection();
s.UseCommercetoolsImportApi(configuration, "Import");
s.UseCommercetoolsApi(configuration, "Client");
var p = s.BuildServiceProvider();

var clients = p.GetServices<IClient>();

var importConfig = configuration.GetSection("Import").Get<ClientConfiguration>();
var apiConfig = configuration.GetSection("Client").Get<ClientConfiguration>();

var importApiRoot = clients.First(client => client.Name == "Import")
.WithImportApi(importConfig.ProjectKey);
var apiRoot = clients.First(client => client.Name == "Client")
.WithProject(apiConfig.ProjectKey);

Assert.Equal("Import", importApiRoot.ClientName);
Assert.Equal("Client", apiRoot.ClientName);

var project = await apiRoot.Get().ExecuteAsync().ConfigureAwait(false);

Assert.Equal(apiConfig.ProjectKey, project.Key);

var importContainers = await importApiRoot.ImportContainers().Get().ExecuteAsync().ConfigureAwait(false);
Assert.NotNull(importContainers);


}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ await WithProduct(_projectApiRoot,
var img = updateProduct.MasterData.Staged.Variants[1].Images.FirstOrDefault();
Assert.NotNull(img);
Assert.Contains("logo", img.Url);

var logoPngPath = @"Resources/ct-logo.png";
var filePng = new FileStream(logoPath, FileMode.Open, FileAccess.Read);
var filePng = new FileStream(logoPngPath, FileMode.Open, FileAccess.Read);

var updateProductPng = await _projectApiRoot
.Products()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
<ProjectReference Include="..\..\commercetools.Base.Client\commercetools.Base.Client.csproj" />
<ProjectReference Include="..\..\commercetools.Base.Serialization\commercetools.Base.Serialization.csproj" />
<ProjectReference Include="..\..\commercetools.Sdk.Api\commercetools.Sdk.Api.csproj" />
<ProjectReference Include="..\..\commercetools.Sdk.ImportApi\commercetools.Sdk.ImportApi.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.test.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="Resources\ct_logo_farbe.gif">
<None Update="Resources\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TestGetByIdRequest()
public void HeaderCaseInsensitive()
{
var headers = new ApiHttpHeaders();

headers.AddHeader("content-type", "text/plain");
Assert.True(headers.HasHeader("Content-Type"));
Assert.True(headers.HasHeader("content-type"));
Expand All @@ -65,7 +65,7 @@ public void HeaderCaseInsensitive()
Assert.Equal(2, headers.GetHeaderValue("Content-type").Count);
Assert.Equal(2, headers.GetHeaders("Content-type").Count);
}

[Fact]
public void TestQueryRequest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static IHttpClientBuilder UseCommercetoolsApi(this IServiceCollection ser
{
clientName
};
services.AddSingleton(c => ApiFactory.Create(c.GetService<IClient>()));
services.AddSingleton(c => ApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName)));
IClientConfiguration clientConfiguration = configuration.GetSection(clientName).Get<ClientConfiguration>();
if (clientConfiguration.ProjectKey != null)
{
services.AddSingleton(c => ApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => ApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
}
return services.UseCommercetoolsApi(configuration, clients,
tokenProviderSupplier ?? CreateDefaultTokenProvider, serializationConfiguration, options).Single().Value;
Expand All @@ -53,7 +53,7 @@ public static IDictionary<string, IHttpClientBuilder> UseCommercetoolsApi(this I
{
IClientConfiguration clientConfiguration =
configuration.GetSection(clientName).Get<ClientConfiguration>();
services.AddSingleton(c => ApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => ApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
});

return services.UseHttpApi(configuration, clients,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ public override HttpRequestMessage Build()
request.Content = new StreamContent(Stream);
if (Headers.HasHeader(ApiHttpHeaders.CONTENT_TYPE))
{
var contentType = Headers.GetFirst(ApiHttpHeaders.CONTENT_TYPE);
request.Content.Headers.ContentType =
new MediaTypeHeaderValue(contentType);
new MediaTypeHeaderValue(Headers.GetFirst(ApiHttpHeaders.CONTENT_TYPE));
}
}
return request;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace commercetools.Sdk.Api.Models.Extensions
{

public partial class GoogleCloudFunctionDestination : IGoogleCloudFunctionDestination
{
public string Type { get; set; }

public string Url { get; set; }
public GoogleCloudFunctionDestination()
{
this.Type = "GoogleCloudFunction";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace commercetools.Sdk.Api.Models.Extensions
[TypeDiscriminator(nameof(Type))]
[DefaultTypeDiscriminator(typeof(commercetools.Sdk.Api.Models.Extensions.ExtensionDestination))]
[SubTypeDiscriminator("AWSLambda", typeof(commercetools.Sdk.Api.Models.Extensions.AWSLambdaDestination))]
[SubTypeDiscriminator("GoogleCloudFunction", typeof(commercetools.Sdk.Api.Models.Extensions.GoogleCloudFunctionDestination))]
[SubTypeDiscriminator("HTTP", typeof(commercetools.Sdk.Api.Models.Extensions.HttpDestination))]
public partial interface IExtensionDestination
{
Expand All @@ -18,6 +19,12 @@ static commercetools.Sdk.Api.Models.Extensions.AWSLambdaDestination AwsLambda(Ac
init?.Invoke(t);
return t;
}
static commercetools.Sdk.Api.Models.Extensions.GoogleCloudFunctionDestination GoogleCloudFunction(Action<commercetools.Sdk.Api.Models.Extensions.GoogleCloudFunctionDestination> init = null)
{
var t = new commercetools.Sdk.Api.Models.Extensions.GoogleCloudFunctionDestination();
init?.Invoke(t);
return t;
}
static commercetools.Sdk.Api.Models.Extensions.HttpDestination Http(Action<commercetools.Sdk.Api.Models.Extensions.HttpDestination> init = null)
{
var t = new commercetools.Sdk.Api.Models.Extensions.HttpDestination();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using commercetools.Base.CustomAttributes;


namespace commercetools.Sdk.Api.Models.Extensions
{
[DeserializeAs(typeof(commercetools.Sdk.Api.Models.Extensions.GoogleCloudFunctionDestination))]
public partial interface IGoogleCloudFunctionDestination : IExtensionDestination
{
string Url { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static IDictionary<string, IHttpClientBuilder> UseCommercetoolsHistoryApi
{
IClientConfiguration clientConfiguration =
configuration.GetSection(clientName).Get<ClientConfiguration>();
services.AddSingleton(c => HistoryApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => HistoryApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
});

return services.UseHttpApi(configuration, clients,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static IHttpClientBuilder UseCommercetoolsImportApi(this IServiceCollecti
{
clientName
};
services.AddSingleton(c => ImportApiFactory.Create(c.GetService<IClient>()));
services.AddSingleton(c => ImportApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName)));
IClientConfiguration clientConfiguration = configuration.GetSection(clientName).Get<ClientConfiguration>();
if (clientConfiguration.ProjectKey != null)
{
services.AddSingleton(c => ImportApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => ImportApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
}

return services.UseCommercetoolsImportApi(configuration, clients, tokenProviderSupplier ?? CreateDefaultTokenProvider, options).Single().Value;
Expand All @@ -45,7 +45,7 @@ public static IDictionary<string, IHttpClientBuilder> UseCommercetoolsImportApi(
{
IClientConfiguration clientConfiguration =
configuration.GetSection(clientName).Get<ClientConfiguration>();
services.AddSingleton(c => ImportApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => ImportApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
});

return services.UseHttpApi(configuration, clients,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public static IHttpClientBuilder UseCommercetoolsMLApi(this IServiceCollection s
{
clientName
};
services.AddSingleton(c => MLApiFactory.Create(c.GetService<IClient>()));
services.AddSingleton(c => MLApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName)));
IClientConfiguration clientConfiguration = configuration.GetSection(clientName).Get<ClientConfiguration>();
if (clientConfiguration.ProjectKey != null)
{
services.AddSingleton(c => MLApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => MLApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
}

return services.UseCommercetoolsMLApi(configuration, clients, tokenProviderSupplier ?? CreateDefaultTokenProvider, options).Single().Value;
Expand All @@ -46,7 +46,7 @@ public static IDictionary<string, IHttpClientBuilder> UseCommercetoolsMLApi(this
{
IClientConfiguration clientConfiguration =
configuration.GetSection(clientName).Get<ClientConfiguration>();
services.AddSingleton(c => MLApiFactory.Create(c.GetService<IClient>(), clientConfiguration.ProjectKey));
services.AddSingleton(c => MLApiFactory.Create(c.GetServices<IClient>().Single(client => client.Name == clientName), clientConfiguration.ProjectKey));
});

return services.UseHttpApi(configuration, clients,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Threading;
using commercetools.Base.Client;
Expand Down Expand Up @@ -87,6 +88,11 @@ public override HttpRequestMessage Build()
if (Stream != null && Stream.Length > 0)
{
request.Content = new StreamContent(Stream);
if (Headers.HasHeader(ApiHttpHeaders.CONTENT_TYPE))
{
request.Content.Headers.ContentType =
new MediaTypeHeaderValue(Headers.GetFirst(ApiHttpHeaders.CONTENT_TYPE));
}
}
return request;
}
Expand Down
1 change: 1 addition & 0 deletions reference.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e0f48f22e6164e9ad9fba9047c7e33907757b0db

0 comments on commit a617205

Please sign in to comment.