Skip to content

Commit 2610db6

Browse files
feat(specs): introduce recommend source in Comp API client (generated)
algolia/api-clients-automation#6227 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Clara Muller <5667350+ClaraMuller@users.noreply.github.com>
1 parent 1ca890d commit 2610db6

6 files changed

Lines changed: 385 additions & 14 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
//
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Text.Json;
9+
using System.Text.Json.Serialization;
10+
using Algolia.Search.Serializer;
11+
12+
namespace Algolia.Search.Models.Composition;
13+
14+
/// <summary>
15+
/// Injected items will originate from a recommendation request performed on the specified index.
16+
/// </summary>
17+
public partial class InjectedItemRecommendSource
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the InjectedItemRecommendSource class.
21+
/// </summary>
22+
[JsonConstructor]
23+
public InjectedItemRecommendSource() { }
24+
25+
/// <summary>
26+
/// Initializes a new instance of the InjectedItemRecommendSource class.
27+
/// </summary>
28+
/// <param name="recommend">recommend (required).</param>
29+
public InjectedItemRecommendSource(Recommend recommend)
30+
{
31+
Recommend = recommend ?? throw new ArgumentNullException(nameof(recommend));
32+
}
33+
34+
/// <summary>
35+
/// Gets or Sets Recommend
36+
/// </summary>
37+
[JsonPropertyName("recommend")]
38+
public Recommend Recommend { get; set; }
39+
40+
/// <summary>
41+
/// Returns the string presentation of the object
42+
/// </summary>
43+
/// <returns>String presentation of the object</returns>
44+
public override string ToString()
45+
{
46+
StringBuilder sb = new StringBuilder();
47+
sb.Append("class InjectedItemRecommendSource {\n");
48+
sb.Append(" Recommend: ").Append(Recommend).Append("\n");
49+
sb.Append("}\n");
50+
return sb.ToString();
51+
}
52+
53+
/// <summary>
54+
/// Returns the JSON string presentation of the object
55+
/// </summary>
56+
/// <returns>JSON string presentation of the object</returns>
57+
public virtual string ToJson()
58+
{
59+
return JsonSerializer.Serialize(this, JsonConfig.Options);
60+
}
61+
62+
/// <summary>
63+
/// Returns true if objects are equal
64+
/// </summary>
65+
/// <param name="obj">Object to be compared</param>
66+
/// <returns>Boolean</returns>
67+
public override bool Equals(object obj)
68+
{
69+
if (obj is not InjectedItemRecommendSource input)
70+
{
71+
return false;
72+
}
73+
74+
return (
75+
Recommend == input.Recommend || (Recommend != null && Recommend.Equals(input.Recommend))
76+
);
77+
}
78+
79+
/// <summary>
80+
/// Gets the hash code
81+
/// </summary>
82+
/// <returns>Hash code</returns>
83+
public override int GetHashCode()
84+
{
85+
unchecked // Overflow is fine, just wrap
86+
{
87+
int hashCode = 41;
88+
if (Recommend != null)
89+
{
90+
hashCode = (hashCode * 59) + Recommend.GetHashCode();
91+
}
92+
return hashCode;
93+
}
94+
}
95+
}

algoliasearch/Models/Composition/InjectedItemSource.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public InjectedItemSource(InjectedItemExternalSource actualInstance)
4242
actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
4343
}
4444

45+
/// <summary>
46+
/// Initializes a new instance of the InjectedItemSource class
47+
/// with a InjectedItemRecommendSource
48+
/// </summary>
49+
/// <param name="actualInstance">An instance of InjectedItemRecommendSource.</param>
50+
public InjectedItemSource(InjectedItemRecommendSource actualInstance)
51+
{
52+
ActualInstance =
53+
actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
54+
}
55+
4556
/// <summary>
4657
/// Gets or Sets ActualInstance
4758
/// </summary>
@@ -67,6 +78,16 @@ public InjectedItemExternalSource AsInjectedItemExternalSource()
6778
return (InjectedItemExternalSource)ActualInstance;
6879
}
6980

81+
/// <summary>
82+
/// Get the actual instance of `InjectedItemRecommendSource`. If the actual instance is not `InjectedItemRecommendSource`,
83+
/// the InvalidClassException will be thrown
84+
/// </summary>
85+
/// <returns>An instance of InjectedItemRecommendSource</returns>
86+
public InjectedItemRecommendSource AsInjectedItemRecommendSource()
87+
{
88+
return (InjectedItemRecommendSource)ActualInstance;
89+
}
90+
7091
/// <summary>
7192
/// Check if the actual instance is of `InjectedItemSearchSource` type.
7293
/// </summary>
@@ -85,6 +106,15 @@ public bool IsInjectedItemExternalSource()
85106
return ActualInstance.GetType() == typeof(InjectedItemExternalSource);
86107
}
87108

109+
/// <summary>
110+
/// Check if the actual instance is of `InjectedItemRecommendSource` type.
111+
/// </summary>
112+
/// <returns>Whether or not the instance is the type</returns>
113+
public bool IsInjectedItemRecommendSource()
114+
{
115+
return ActualInstance.GetType() == typeof(InjectedItemRecommendSource);
116+
}
117+
88118
/// <summary>
89119
/// Returns the string presentation of the object
90120
/// </summary>
@@ -200,6 +230,22 @@ JsonSerializerOptions options
200230
);
201231
}
202232
}
233+
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("recommend", out _))
234+
{
235+
try
236+
{
237+
return new InjectedItemSource(
238+
jsonDocument.Deserialize<InjectedItemRecommendSource>(JsonConfig.Options)
239+
);
240+
}
241+
catch (Exception exception)
242+
{
243+
// deserialization failed, try the next one
244+
System.Diagnostics.Debug.WriteLine(
245+
$"Failed to deserialize into InjectedItemRecommendSource: {exception}"
246+
);
247+
}
248+
}
203249
throw new InvalidDataException(
204250
$"The JSON string cannot be deserialized into any schema defined."
205251
);

algoliasearch/Models/Composition/MainRecommend.cs

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ namespace Algolia.Search.Models.Composition;
1616
/// </summary>
1717
public partial class MainRecommend
1818
{
19+
/// <summary>
20+
/// Gets or Sets Model
21+
/// </summary>
22+
[JsonPropertyName("model")]
23+
public Model? Model { get; set; }
24+
1925
/// <summary>
2026
/// Initializes a new instance of the MainRecommend class.
2127
/// </summary>
@@ -25,18 +31,41 @@ public MainRecommend() { }
2531
/// <summary>
2632
/// Initializes a new instance of the MainRecommend class.
2733
/// </summary>
28-
/// <param name="index">Targeted index name. (required).</param>
29-
public MainRecommend(string index)
34+
/// <param name="indexName">Index to retrieve recommendations from. (required).</param>
35+
/// <param name="model">model (required).</param>
36+
/// <param name="threshold">Minimum score a recommendation must have to be included. (required).</param>
37+
public MainRecommend(string indexName, Model? model, int threshold)
3038
{
31-
Index = index ?? throw new ArgumentNullException(nameof(index));
39+
IndexName = indexName ?? throw new ArgumentNullException(nameof(indexName));
40+
Model = model;
41+
Threshold = threshold;
3242
}
3343

3444
/// <summary>
35-
/// Targeted index name.
45+
/// Index to retrieve recommendations from.
46+
/// </summary>
47+
/// <value>Index to retrieve recommendations from.</value>
48+
[JsonPropertyName("indexName")]
49+
public string IndexName { get; set; }
50+
51+
/// <summary>
52+
/// Minimum score a recommendation must have to be included.
53+
/// </summary>
54+
/// <value>Minimum score a recommendation must have to be included.</value>
55+
[JsonPropertyName("threshold")]
56+
public int Threshold { get; set; }
57+
58+
/// <summary>
59+
/// Gets or Sets QueryParameters
60+
/// </summary>
61+
[JsonPropertyName("queryParameters")]
62+
public MainInjectionQueryParameters QueryParameters { get; set; }
63+
64+
/// <summary>
65+
/// Gets or Sets FallbackParameters
3666
/// </summary>
37-
/// <value>Targeted index name.</value>
38-
[JsonPropertyName("index")]
39-
public string Index { get; set; }
67+
[JsonPropertyName("fallbackParameters")]
68+
public MainInjectionQueryParameters FallbackParameters { get; set; }
4069

4170
/// <summary>
4271
/// Returns the string presentation of the object
@@ -46,7 +75,11 @@ public override string ToString()
4675
{
4776
StringBuilder sb = new StringBuilder();
4877
sb.Append("class MainRecommend {\n");
49-
sb.Append(" Index: ").Append(Index).Append("\n");
78+
sb.Append(" IndexName: ").Append(IndexName).Append("\n");
79+
sb.Append(" Model: ").Append(Model).Append("\n");
80+
sb.Append(" Threshold: ").Append(Threshold).Append("\n");
81+
sb.Append(" QueryParameters: ").Append(QueryParameters).Append("\n");
82+
sb.Append(" FallbackParameters: ").Append(FallbackParameters).Append("\n");
5083
sb.Append("}\n");
5184
return sb.ToString();
5285
}
@@ -72,7 +105,19 @@ public override bool Equals(object obj)
72105
return false;
73106
}
74107

75-
return (Index == input.Index || (Index != null && Index.Equals(input.Index)));
108+
return (
109+
IndexName == input.IndexName || (IndexName != null && IndexName.Equals(input.IndexName))
110+
)
111+
&& (Model == input.Model || Model.Equals(input.Model))
112+
&& (Threshold == input.Threshold || Threshold.Equals(input.Threshold))
113+
&& (
114+
QueryParameters == input.QueryParameters
115+
|| (QueryParameters != null && QueryParameters.Equals(input.QueryParameters))
116+
)
117+
&& (
118+
FallbackParameters == input.FallbackParameters
119+
|| (FallbackParameters != null && FallbackParameters.Equals(input.FallbackParameters))
120+
);
76121
}
77122

78123
/// <summary>
@@ -84,9 +129,19 @@ public override int GetHashCode()
84129
unchecked // Overflow is fine, just wrap
85130
{
86131
int hashCode = 41;
87-
if (Index != null)
132+
if (IndexName != null)
133+
{
134+
hashCode = (hashCode * 59) + IndexName.GetHashCode();
135+
}
136+
hashCode = (hashCode * 59) + Model.GetHashCode();
137+
hashCode = (hashCode * 59) + Threshold.GetHashCode();
138+
if (QueryParameters != null)
139+
{
140+
hashCode = (hashCode * 59) + QueryParameters.GetHashCode();
141+
}
142+
if (FallbackParameters != null)
88143
{
89-
hashCode = (hashCode * 59) + Index.GetHashCode();
144+
hashCode = (hashCode * 59) + FallbackParameters.GetHashCode();
90145
}
91146
return hashCode;
92147
}

algoliasearch/Models/Composition/MainSearch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public MainSearch() { }
2525
/// <summary>
2626
/// Initializes a new instance of the MainSearch class.
2727
/// </summary>
28-
/// <param name="index">Targeted index name. (required).</param>
28+
/// <param name="index">Index to retrieve search results from. (required).</param>
2929
public MainSearch(string index)
3030
{
3131
Index = index ?? throw new ArgumentNullException(nameof(index));
3232
}
3333

3434
/// <summary>
35-
/// Targeted index name.
35+
/// Index to retrieve search results from.
3636
/// </summary>
37-
/// <value>Targeted index name.</value>
37+
/// <value>Index to retrieve search results from.</value>
3838
[JsonPropertyName("index")]
3939
public string Index { get; set; }
4040

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
//
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Text.Json;
9+
using System.Text.Json.Serialization;
10+
using Algolia.Search.Serializer;
11+
12+
namespace Algolia.Search.Models.Composition;
13+
14+
/// <summary>
15+
/// Recommendation model to use for retrieving recommendations.
16+
/// </summary>
17+
/// <value>Recommendation model to use for retrieving recommendations.</value>
18+
[JsonConverter(typeof(Serializer.JsonStringEnumConverter<Model>))]
19+
public enum Model
20+
{
21+
/// <summary>
22+
/// Enum TrendingItems for value: trending-items
23+
/// </summary>
24+
[JsonPropertyName("trending-items")]
25+
TrendingItems = 1,
26+
}

0 commit comments

Comments
 (0)