Skip to content

Commit dd43261

Browse files
Feature/update nuget 1 156 0 (#26)
* Regenerated with new version 1.156.0 and bumped .NET to 8.0 * Removed para tags from generated documentation * Removed c tags from generated documentation * Removed example tags from generated documentation * Bumped dotnet-version from 7.0.x to 8.0.x * Handle three generic params and add overwritten constructor for ProductDataRelenvanceModifier * Replaced chained Replace() calls with regex that captures all cases * Removed types that were no longer part of the API. * Updated to be able to generate creator method that sets properties not owned directly by the type. * Removed unrelated change in test. * Fixed breaking change for `ProductRecentlyPurchasedByCompanyFilter.php`. * Fixed breaking change for `ProductRecentlyPurchasedByUserCompanyFilter.php`. * Fixed breaking change for `ProductRecentlyPurchasedByUserFilter.php`. * Fixed breaking change for `ProductRecentlyPurchasedByUserRelevanceModifier.php`. * Fixed breaking change for `ProductRecentlyViewedByCompanyFilter.php`. * Fixed breaking change in `ProductRecentlyViewedByUserFilter.php`. * Fixed breaking change for `ProductRecentlyViewedByUserRelevanceModifier.php`. * Fixed breaking change for `VariantDataRelevanceModifier.php`. * Added support for see-tag langword de-referencing. * Added remarks for nullable value type flag. --------- Co-authored-by: KSGRelewise <119578211+KSGRelewise@users.noreply.github.com>
1 parent eea10d7 commit dd43261

File tree

225 files changed

+3341
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+3341
-488
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212

1313
- uses: php-actions/composer@v6
1414

15-
- name: Setup .NET 7 preview
15+
- name: Setup .NET 8 preview
1616
uses: actions/setup-dotnet@v1
1717
with:
18-
dotnet-version: '7.0.x'
18+
dotnet-version: '8.0.x'
1919

2020
- name: Generate PHP classes
2121
run: ./generate.sh

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313

1414
- uses: php-actions/composer@v5
1515

16-
- name: Setup .NET 7 preview
16+
- name: Setup .NET 8 preview
1717
uses: actions/setup-dotnet@v1
1818
with:
19-
dotnet-version: '7.0.x'
19+
dotnet-version: '8.0.x'
2020

2121
- name: Generate PHP classes
2222
run: ./generate.sh

Generator/Generator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="AngleSharp.Xml" Version="1.0.0" />
12-
<PackageReference Include="Relewise.Client" Version="1.130.0" />
12+
<PackageReference Include="Relewise.Client" Version="1.156.0" />
1313
</ItemGroup>
1414

1515
</Project>

Generator/PhpMemberWriters/PhpCreatorMethodWriter.cs

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,45 @@
33
using System.Globalization;
44
using System.Reflection;
55
using Relewise.Client.Requests;
6+
using Relewise.Client.Requests.RelevanceModifiers;
7+
using Relewise.Client.Requests.Conditions;
8+
using Relewise.Client.Requests.ValueSelectors;
9+
using Relewise.Client.Requests.Filters;
610

711
namespace Generator.PhpMemberWriters;
812

913
public class PhpCreatorMethodWriter
1014
{
1115
private readonly Dictionary<Type, ConstructorInfo> overrideDefaultConstructors = new()
1216
{
13-
[typeof(Channel)] = typeof(Channel).GetConstructor(new[] { typeof(string) })! // We override any matching logic and choose the constructor with one string parameter.
17+
// We override any matching logic and choose the constructor with one string parameter.
18+
[typeof(Channel)] = typeof(Channel).GetConstructor(new[] { typeof(string) })!,
19+
// For backwards compatibility remove in next major release.
20+
[typeof(ProductDataRelevanceModifier)] = typeof(ProductDataRelevanceModifier).GetConstructor(new[] { typeof(string), typeof(List<ValueCondition>), typeof(ValueSelector), typeof(bool), typeof(bool) })!,
21+
// For backwards compatibility remove in next major release.
22+
[typeof(ProductRecentlyViewedByUserFilter)] = typeof(ProductRecentlyViewedByUserFilter).GetConstructor(new[] { typeof(DateTimeOffset), typeof(bool) })!,
23+
// For backwards compatibility remove in next major release.
24+
[typeof(ProductRecentlyViewedByUserRelevanceModifier)] = typeof(ProductRecentlyViewedByUserRelevanceModifier).GetConstructor(new[] { typeof(DateTimeOffset), typeof(double), typeof(double) })!,
25+
// For backwards compatibility remove in next major release.
26+
[typeof(VariantDataRelevanceModifier)] = typeof(VariantDataRelevanceModifier).GetConstructor(new[] { typeof(string), typeof(List<ValueCondition>), typeof(ValueSelector), typeof(bool), typeof(bool) })!,
27+
};
28+
29+
/// <summary>
30+
/// We sometimes change the types that own specific properties so that the optimistic parameter matcher can no longer find the properties in the same way as previously.
31+
/// In this case we can define manual mappings that select which parameters should be mapped to keep the generated code from breaking.
32+
/// </summary>
33+
private readonly Dictionary<Type, (ConstructorInfo constructor, string[] parameters)> overrideDefaultConstructorsWithSelectedParameters = new()
34+
{
35+
// For backwards compatibility remove in next major release.
36+
[typeof(ProductRecentlyPurchasedByCompanyFilter)] = (typeof(ProductRecentlyPurchasedByCompanyFilter).GetConstructor(new[] { typeof(DateTimeOffset), typeof(string), typeof(bool) })!, new []{ "sinceUtc", "negated" }),
37+
// For backwards compatibility remove in next major release.
38+
[typeof(ProductRecentlyPurchasedByUserCompanyFilter)] = (typeof(ProductRecentlyPurchasedByUserCompanyFilter).GetConstructor(new[] { typeof(DateTimeOffset), typeof(bool) })!, new[] { "sinceUtc", "negated" }),
39+
// For backwards compatibility remove in next major release.
40+
[typeof(ProductRecentlyPurchasedByUserFilter)] = (typeof(ProductRecentlyPurchasedByUserFilter).GetConstructor(new[] { typeof(DateTimeOffset), typeof(bool) })!, new[] { "sinceUtc", "negated" }),
41+
// For backwards compatibility remove in next major release.
42+
[typeof(ProductRecentlyPurchasedByUserRelevanceModifier)] = (typeof(ProductRecentlyPurchasedByUserRelevanceModifier).GetConstructor(new[] { typeof(DateTimeOffset), typeof(double), typeof(double) })!, new[] { "sinceUtc", "ifPreviouslyPurchasedByUserMultiplyWeightBy", "ifNotPreviouslyPurchasedByUserMultiplyWeightBy" }),
43+
// For backwards compatibility remove in next major release.
44+
[typeof(ProductRecentlyViewedByCompanyFilter)] = (typeof(ProductRecentlyViewedByCompanyFilter).GetConstructor(new[] { typeof(DateTimeOffset), typeof(string), typeof(bool) })!, new[] { "sinceUtc", "negated" }),
1445
};
1546

1647
private readonly PhpWriter phpWriter;
@@ -20,7 +51,9 @@ public PhpCreatorMethodWriter(PhpWriter phpWriter)
2051
this.phpWriter = phpWriter;
2152
}
2253

23-
public void Write(IndentedTextWriter writer, Type type, string typeName, (PropertyInfo info, string propertyTypeName, string propertyName, string lowerCaseName)[] propertyInformations)
54+
public void Write(IndentedTextWriter writer, Type type, string typeName,
55+
(PropertyInfo info, string propertyTypeName, string propertyName, string lowerCaseName)[] settablePropertyInformations,
56+
(PropertyInfo info, string propertyTypeName, string propertyName, string lowerCaseName)[] ownedPropertyInformations)
2457
{
2558
if (type.IsAbstract || type.IsInterface) return;
2659

@@ -31,9 +64,9 @@ public void Write(IndentedTextWriter writer, Type type, string typeName, (Proper
3164

3265
var coveringUniqueTypeMappableConstructorParameters = allConstructors
3366
.FirstOrDefault(c => c.GetParameters().Length == c.GetParameters().DistinctBy(parameter => parameter.ParameterType).Count() // There are no parameters with the same type.
34-
&& c.GetParameters().Length == propertyInformations.Length // There are as many parameters as there are properties.
67+
&& c.GetParameters().Length == ownedPropertyInformations.Length // There are as many parameters as there are properties.
3568
&& c.GetParameters()
36-
.All(parameter => propertyInformations
69+
.All(parameter => ownedPropertyInformations
3770
.Any(property => ParameterIsPersuadableIntoPropertyType(property.info, parameter))
3871
) // There is a property type that matches each parameter type.
3972
)
@@ -42,7 +75,7 @@ public void Write(IndentedTextWriter writer, Type type, string typeName, (Proper
4275

4376
var coveringTypeAndNameMappableConstructorParameters = allConstructors
4477
.Where(c => c.GetParameters()
45-
.All(parameter => propertyInformations
78+
.All(parameter => ownedPropertyInformations
4679
.Count(property =>
4780
ContainedWithinEitherOne(property.propertyName, parameter.Name)
4881
&& ParameterIsPersuadableIntoPropertyType(property.info, parameter)) == 1
@@ -85,8 +118,34 @@ public void Write(IndentedTextWriter writer, Type type, string typeName, (Proper
85118

86119
foreach (var parameter in parameters)
87120
{
88-
var propertyName = propertyInformations
89-
.Single(property => ContainedWithinEitherOne(property.propertyName, parameter.Name) && ParameterIsPersuadableIntoPropertyType(property.info, parameter))
121+
// We use settablePropertyInformations here as the only place as it was an error originally that we didn't use it, but it would create too many breaking changes if we corrected in all places.
122+
var propertyName = settablePropertyInformations
123+
.Single(property => ContainedWithinEitherOne(property.propertyName, parameter.Name) && ParameterIsPersuadableIntoPropertyType(property.info, parameter, supportNullableValueTypes: true))
124+
.lowerCaseName;
125+
126+
writer.WriteLine($"$result->{propertyName} = ${parameter.Name};");
127+
}
128+
}
129+
else if (overrideDefaultConstructorsWithSelectedParameters.TryGetValue(type, out (ConstructorInfo defaultConstructor, string[] parameters) overriden))
130+
{
131+
var parameters = overriden.defaultConstructor.GetParameters().Where(p => overriden.parameters.Contains(p.Name)).ToArray();
132+
133+
writer.WriteCommentBlock(
134+
parameters.Select(p => phpWriter.XmlDocumentation.GetConstructorParam(typeName, parameters, p))
135+
.Prepend(phpWriter.XmlDocumentation.GetConstructorSummary(typeName, parameters))
136+
.ToArray()
137+
);
138+
139+
writer.WriteLine($"public static function create({ParameterList(parameters)}) : {typeName}");
140+
writer.WriteLine("{");
141+
writer.Indent++;
142+
writer.WriteLine($"$result = new {typeName}();");
143+
144+
foreach (var parameter in parameters)
145+
{
146+
// We use settablePropertyInformations here as the only place as it was an error originally that we didn't use it, but it would create too many breaking changes if we corrected in all places.
147+
var propertyName = settablePropertyInformations
148+
.Single(property => ContainedWithinEitherOne(property.propertyName, parameter.Name) && ParameterIsPersuadableIntoPropertyType(property.info, parameter, supportNullableValueTypes: true))
90149
.lowerCaseName;
91150

92151
writer.WriteLine($"$result->{propertyName} = ${parameter.Name};");
@@ -107,7 +166,7 @@ public void Write(IndentedTextWriter writer, Type type, string typeName, (Proper
107166

108167
foreach (var parameter in coveringUniqueTypeMappableConstructorParameters)
109168
{
110-
var propertyName = propertyInformations
169+
var propertyName = ownedPropertyInformations
111170
.Single(property => ParameterIsPersuadableIntoPropertyType(property.info, parameter))
112171
.lowerCaseName;
113172

@@ -129,7 +188,7 @@ public void Write(IndentedTextWriter writer, Type type, string typeName, (Proper
129188

130189
foreach (var parameter in coveringTypeAndNameMappableConstructorParameters)
131190
{
132-
var propertyName = propertyInformations
191+
var propertyName = ownedPropertyInformations
133192
.Single(property => ContainedWithinEitherOne(property.propertyName, parameter.Name) && ParameterIsPersuadableIntoPropertyType(property.info, parameter))
134193
.lowerCaseName;
135194

@@ -254,28 +313,37 @@ private static bool EqualCollectionElementType(Type type1, Type type2)
254313
|| EnumerableTypeArgumentMatchesSecondEnumerableType(type1, type2);
255314
}
256315

257-
private static bool ParameterIsPersuadableIntoPropertyType(PropertyInfo property, ParameterInfo parameter)
316+
/// <remarks>
317+
/// On next major release <paramref name="supportNullableValueTypes"/> should be removed and this should be rewritten to have it always apply.
318+
/// </remarks>
319+
/// <param name="supportNullableValueTypes">This is introduced as we previously did not support matching on nullable value types. So setting this to <see langword="true"/> would be breaking for most places.</param>
320+
private static bool ParameterIsPersuadableIntoPropertyType(PropertyInfo property, ParameterInfo parameter, bool supportNullableValueTypes = false)
258321
{
259322
if (EqualCollectionElementType(property.PropertyType, parameter.ParameterType))
260323
{
261324
return true;
262325
}
263326

264-
if (property.PropertyType != parameter.ParameterType)
265-
{
266-
return false;
267-
}
327+
Type propertyType = supportNullableValueTypes && property.PropertyType.IsConstructedGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) ? property.PropertyType.GetGenericArguments()[0] : property.PropertyType;
328+
Type parameterType = supportNullableValueTypes && parameter.ParameterType.IsConstructedGenericType && parameter.ParameterType.GetGenericTypeDefinition() == typeof(Nullable<>) ? parameter.ParameterType.GetGenericArguments()[0] : parameter.ParameterType;
268329

269330
var propertyNullabilityContext = new NullabilityInfoContext().Create(property);
270331
var parameterNullabilityContext = new NullabilityInfoContext().Create(parameter);
271332

272-
if (propertyNullabilityContext.WriteState is NullabilityState.Nullable)
333+
bool propertyIsNullable = property.PropertyType != propertyType || propertyNullabilityContext.WriteState is NullabilityState.Nullable;
334+
bool parameterIsNullable = parameter.ParameterType != parameterType || parameterNullabilityContext.WriteState is NullabilityState.Nullable;
335+
336+
if (propertyType != parameterType)
337+
{
338+
return false;
339+
}
340+
341+
if (propertyIsNullable)
273342
{
274343
return true;
275344
}
276345

277-
if (propertyNullabilityContext.WriteState is NullabilityState.Nullable
278-
== parameterNullabilityContext.WriteState is NullabilityState.Nullable)
346+
if (!propertyIsNullable && !parameterIsNullable)
279347
{
280348
return true;
281349
}

Generator/PhpTypeResolver.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Reflection;
2+
using System.Text.RegularExpressions;
23

34
namespace Generator;
45

@@ -48,12 +49,14 @@ private string GetOrAddTypeDefinition(Type type)
4849

4950
private static string GetTypeName(Type type)
5051
{
52+
var name = Regex.Replace(type.Name, @"`\d+", "");
53+
5154
if (type.IsNested)
5255
{
53-
return type.DeclaringType!.Name + type.Name.Replace("`1", "").Replace("`2", "");
56+
return type.DeclaringType!.Name + name;
5457
}
5558

56-
return type.Name.Replace("`1", "").Replace("`2", "");
59+
return name;
5760
}
5861

5962
private string AddCollectionTypeDefinition(Type type)

Generator/PhpTypeWriters/PhpClassWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace {Constants.Namespace};
8282
phpWriter.PhpSettablePropertiesWriter.Write(writer, type, ownedProperties);
8383
phpWriter.PhpStaticReadonlyPropertiesWriter.Write(writer, staticGetterProperties);
8484

85-
phpWriter.PhpCreatorMethodWriter.Write(writer, type, typeName, ownedProperties);
85+
phpWriter.PhpCreatorMethodWriter.Write(writer, type, typeName, settableProperties, ownedProperties);
8686
phpWriter.PhpHydrationMethodsWriter.Write(writer, type, typeName, ownedProperties);
8787
phpWriter.PhpPropertySetterMethodsWriter.Write(writer, type, settableProperties);
8888

Generator/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
var assembly = Assembly.GetAssembly(typeof(ClientBase)) ?? throw new ArgumentException("Could not load Relewise Client assembly.");
2020

21-
var xmlDocumentation = await XMLDocsFetcher.Get("Relewise.Client", "1.130.0");
21+
var xmlDocumentation = await XMLDocsFetcher.Get("Relewise.Client", "1.156.0");
2222

2323
Console.WriteLine($"Loaded {xmlDocumentation.Summaries.Count} documentation summaries.");
2424
Console.WriteLine($"Loaded {xmlDocumentation.Params.Count} documentation params.");

Generator/XMLDocsFetcher.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static async Task<XmlDocumentation> Get(string package, string version)
3030
var document = await context.OpenAsync(req => req.Content(content.Replace("/>", "></SEE>")));
3131
foreach (var seeReference in document.QuerySelectorAll("see"))
3232
{
33-
seeReference.OuterHtml = seeReference.GetAttribute("cref")?.Split(".").Last() ?? string.Empty;
33+
seeReference.OuterHtml = seeReference.GetAttribute("cref")?.Split(".").Last() ?? seeReference.GetAttribute("langword")?.Split(".").Last() ?? string.Empty;
3434
}
3535

3636
foreach (var member in document.GetElementsByTagName("doc")[0].Children[1].Children)
@@ -43,11 +43,19 @@ public static async Task<XmlDocumentation> Get(string package, string version)
4343
{
4444
summaryWrapper.OuterHtml = summaryWrapper.InnerHtml.Trim();
4545
}
46-
foreach (var seeReference in child.Children.Where(c => c.TagName == "SEE"))
46+
foreach (var paraWrapper in child.Children.Where(c => c.TagName == "PARA"))
4747
{
48-
seeReference.OuterHtml = seeReference.GetAttribute("cref")?.Split(".").Last() ?? string.Empty;
48+
paraWrapper.OuterHtml = paraWrapper.InnerHtml.Trim();
4949
}
50-
50+
foreach (var cWrapper in child.Children.Where(c => c.TagName == "C"))
51+
{
52+
cWrapper.OuterHtml = cWrapper.InnerHtml.Trim();
53+
}
54+
foreach (var exampleWrapper in child.Children.Where(c => c.TagName == "EXAMPLE"))
55+
{
56+
exampleWrapper.OuterHtml = exampleWrapper.InnerHtml.Trim();
57+
}
58+
5159
result.Summaries.TryAdd(member.GetAttribute("name")!, HttpUtility.HtmlDecode(JoinInOneLine(child.InnerHtml)));
5260
}
5361
else if (child.TagName is "PARAM" && child.NextSibling?.TextContent is { Length: > 0 } text)

src/Models/AbandonedCartTriggerResultTriggerConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
abstract class AbandonedCartTriggerResultTriggerConfiguration extends TriggerConfiguration
88
{
9-
public string $typeDefinition = "Relewise.Client.DataTypes.Triggers.Configurations.TriggerConfiguration`1[[Relewise.Client.Responses.Triggers.Results.AbandonedCartTriggerResult, Relewise.Client, Version=1.130.0.0, Culture=neutral, PublicKeyToken=null]], Relewise.Client";
9+
public string $typeDefinition = "Relewise.Client.DataTypes.Triggers.Configurations.TriggerConfiguration`1[[Relewise.Client.Responses.Triggers.Results.AbandonedCartTriggerResult, Relewise.Client, Version=1.156.0.0, Culture=neutral, PublicKeyToken=null]], Relewise.Client";
1010
public static function hydrate(array $arr)
1111
{
1212
$type = $arr["\$type"];

src/Models/AbandonedSearchTriggerResultTriggerConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
abstract class AbandonedSearchTriggerResultTriggerConfiguration extends TriggerConfiguration
88
{
9-
public string $typeDefinition = "Relewise.Client.DataTypes.Triggers.Configurations.TriggerConfiguration`1[[Relewise.Client.Responses.Triggers.Results.AbandonedSearchTriggerResult, Relewise.Client, Version=1.130.0.0, Culture=neutral, PublicKeyToken=null]], Relewise.Client";
9+
public string $typeDefinition = "Relewise.Client.DataTypes.Triggers.Configurations.TriggerConfiguration`1[[Relewise.Client.Responses.Triggers.Results.AbandonedSearchTriggerResult, Relewise.Client, Version=1.156.0.0, Culture=neutral, PublicKeyToken=null]], Relewise.Client";
1010
public static function hydrate(array $arr)
1111
{
1212
$type = $arr["\$type"];

0 commit comments

Comments
 (0)