Skip to content

Commit c7c68ff

Browse files
algolia-botFluf22
andcommitted
fix(kotlin): deserialization (#3822) (generated) [skip ci]
Co-authored-by: Thomas Raffray <[email protected]>
1 parent 4e82751 commit c7c68ff

File tree

54 files changed

+756
-81
lines changed

Some content is hidden

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

54 files changed

+756
-81
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Models/Recommend/RecommendationsHit.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ public partial class RecommendationsHit : AbstractSchema
2222
{
2323
/// <summary>
2424
/// Initializes a new instance of the RecommendationsHit class
25-
/// with a RecommendHit
25+
/// with a TrendingFacetHit
2626
/// </summary>
27-
/// <param name="actualInstance">An instance of RecommendHit.</param>
28-
public RecommendationsHit(RecommendHit actualInstance)
27+
/// <param name="actualInstance">An instance of TrendingFacetHit.</param>
28+
public RecommendationsHit(TrendingFacetHit actualInstance)
2929
{
3030
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
3131
}
3232

3333
/// <summary>
3434
/// Initializes a new instance of the RecommendationsHit class
35-
/// with a TrendingFacetHit
35+
/// with a RecommendHit
3636
/// </summary>
37-
/// <param name="actualInstance">An instance of TrendingFacetHit.</param>
38-
public RecommendationsHit(TrendingFacetHit actualInstance)
37+
/// <param name="actualInstance">An instance of RecommendHit.</param>
38+
public RecommendationsHit(RecommendHit actualInstance)
3939
{
4040
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
4141
}
@@ -47,42 +47,42 @@ public RecommendationsHit(TrendingFacetHit actualInstance)
4747
public sealed override object ActualInstance { get; set; }
4848

4949
/// <summary>
50-
/// Get the actual instance of `RecommendHit`. If the actual instance is not `RecommendHit`,
50+
/// Get the actual instance of `TrendingFacetHit`. If the actual instance is not `TrendingFacetHit`,
5151
/// the InvalidClassException will be thrown
5252
/// </summary>
53-
/// <returns>An instance of RecommendHit</returns>
54-
public RecommendHit AsRecommendHit()
53+
/// <returns>An instance of TrendingFacetHit</returns>
54+
public TrendingFacetHit AsTrendingFacetHit()
5555
{
56-
return (RecommendHit)ActualInstance;
56+
return (TrendingFacetHit)ActualInstance;
5757
}
5858

5959
/// <summary>
60-
/// Get the actual instance of `TrendingFacetHit`. If the actual instance is not `TrendingFacetHit`,
60+
/// Get the actual instance of `RecommendHit`. If the actual instance is not `RecommendHit`,
6161
/// the InvalidClassException will be thrown
6262
/// </summary>
63-
/// <returns>An instance of TrendingFacetHit</returns>
64-
public TrendingFacetHit AsTrendingFacetHit()
63+
/// <returns>An instance of RecommendHit</returns>
64+
public RecommendHit AsRecommendHit()
6565
{
66-
return (TrendingFacetHit)ActualInstance;
66+
return (RecommendHit)ActualInstance;
6767
}
6868

6969

7070
/// <summary>
71-
/// Check if the actual instance is of `RecommendHit` type.
71+
/// Check if the actual instance is of `TrendingFacetHit` type.
7272
/// </summary>
7373
/// <returns>Whether or not the instance is the type</returns>
74-
public bool IsRecommendHit()
74+
public bool IsTrendingFacetHit()
7575
{
76-
return ActualInstance.GetType() == typeof(RecommendHit);
76+
return ActualInstance.GetType() == typeof(TrendingFacetHit);
7777
}
7878

7979
/// <summary>
80-
/// Check if the actual instance is of `TrendingFacetHit` type.
80+
/// Check if the actual instance is of `RecommendHit` type.
8181
/// </summary>
8282
/// <returns>Whether or not the instance is the type</returns>
83-
public bool IsTrendingFacetHit()
83+
public bool IsRecommendHit()
8484
{
85-
return ActualInstance.GetType() == typeof(TrendingFacetHit);
85+
return ActualInstance.GetType() == typeof(RecommendHit);
8686
}
8787

8888
/// <summary>
@@ -169,28 +169,28 @@ public override RecommendationsHit Read(ref Utf8JsonReader reader, Type typeToCo
169169
{
170170
var jsonDocument = JsonDocument.ParseValue(ref reader);
171171
var root = jsonDocument.RootElement;
172-
if (root.ValueKind == JsonValueKind.Object)
172+
if (root.ValueKind == JsonValueKind.Object && root.TryGetProperty("facetName", out _) && root.TryGetProperty("facetValue", out _))
173173
{
174174
try
175175
{
176-
return new RecommendationsHit(jsonDocument.Deserialize<RecommendHit>(JsonConfig.Options));
176+
return new RecommendationsHit(jsonDocument.Deserialize<TrendingFacetHit>(JsonConfig.Options));
177177
}
178178
catch (Exception exception)
179179
{
180180
// deserialization failed, try the next one
181-
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into RecommendHit: {exception}");
181+
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into TrendingFacetHit: {exception}");
182182
}
183183
}
184184
if (root.ValueKind == JsonValueKind.Object)
185185
{
186186
try
187187
{
188-
return new RecommendationsHit(jsonDocument.Deserialize<TrendingFacetHit>(JsonConfig.Options));
188+
return new RecommendationsHit(jsonDocument.Deserialize<RecommendHit>(JsonConfig.Options));
189189
}
190190
catch (Exception exception)
191191
{
192192
// deserialization failed, try the next one
193-
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into TrendingFacetHit: {exception}");
193+
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into RecommendHit: {exception}");
194194
}
195195
}
196196
throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined.");

clients/algoliasearch-client-go/algolia/recommend/model_recommendations_hit.go

Lines changed: 27 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/recommend/RecommendationsHit.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ class Deserializer extends JsonDeserializer<RecommendationsHit> {
4949
@Override
5050
public RecommendationsHit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
5151
JsonNode tree = jp.readValueAsTree();
52-
// deserialize RecommendHit
53-
if (tree.isObject()) {
52+
// deserialize TrendingFacetHit
53+
if (tree.isObject() && tree.has("facetName") && tree.has("facetValue")) {
5454
try (JsonParser parser = tree.traverse(jp.getCodec())) {
55-
RecommendHit value = parser.readValueAs(RecommendHit.class);
56-
return new RecommendationsHit.RecommendHitWrapper(value);
55+
return parser.readValueAs(TrendingFacetHit.class);
5756
} catch (Exception e) {
5857
// deserialization failed, continue
59-
LOGGER.finest("Failed to deserialize oneOf RecommendHit (error: " + e.getMessage() + ") (type: RecommendHit)");
58+
LOGGER.finest("Failed to deserialize oneOf TrendingFacetHit (error: " + e.getMessage() + ") (type: TrendingFacetHit)");
6059
}
6160
}
62-
// deserialize TrendingFacetHit
61+
// deserialize RecommendHit
6362
if (tree.isObject()) {
6463
try (JsonParser parser = tree.traverse(jp.getCodec())) {
65-
return parser.readValueAs(TrendingFacetHit.class);
64+
RecommendHit value = parser.readValueAs(RecommendHit.class);
65+
return new RecommendationsHit.RecommendHitWrapper(value);
6666
} catch (Exception e) {
6767
// deserialization failed, continue
68-
LOGGER.finest("Failed to deserialize oneOf TrendingFacetHit (error: " + e.getMessage() + ") (type: TrendingFacetHit)");
68+
LOGGER.finest("Failed to deserialize oneOf RecommendHit (error: " + e.getMessage() + ") (type: RecommendHit)");
6969
}
7070
}
7171
throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree));

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/AddABTestsVariant.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.serialization.builtins.*
88
import kotlinx.serialization.descriptors.*
99
import kotlinx.serialization.encoding.*
1010
import kotlinx.serialization.json.*
11+
import kotlin.jvm.JvmInline
1112

1213
/**
1314
* AddABTestsVariant
@@ -18,8 +19,22 @@ import kotlinx.serialization.json.*
1819
*/
1920
@Serializable(AddABTestsVariantSerializer::class)
2021
public sealed interface AddABTestsVariant {
22+
@Serializable
23+
@JvmInline
24+
public value class AbTestsVariantSearchParamsValue(public val value: AbTestsVariantSearchParams) : AddABTestsVariant
25+
26+
@Serializable
27+
@JvmInline
28+
public value class AbTestsVariantValue(public val value: AbTestsVariant) : AddABTestsVariant
2129

2230
public companion object {
31+
32+
public fun of(value: AbTestsVariantSearchParams): AddABTestsVariant {
33+
return AbTestsVariantSearchParamsValue(value)
34+
}
35+
public fun of(value: AbTestsVariant): AddABTestsVariant {
36+
return AbTestsVariantValue(value)
37+
}
2338
}
2439
}
2540

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/analytics/GetTopHitsResponse.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.serialization.builtins.*
88
import kotlinx.serialization.descriptors.*
99
import kotlinx.serialization.encoding.*
1010
import kotlinx.serialization.json.*
11+
import kotlin.jvm.JvmInline
1112

1213
/**
1314
* GetTopHitsResponse
@@ -19,8 +20,29 @@ import kotlinx.serialization.json.*
1920
*/
2021
@Serializable(GetTopHitsResponseSerializer::class)
2122
public sealed interface GetTopHitsResponse {
23+
@Serializable
24+
@JvmInline
25+
public value class TopHitsResponseValue(public val value: TopHitsResponse) : GetTopHitsResponse
26+
27+
@Serializable
28+
@JvmInline
29+
public value class TopHitsResponseWithAnalyticsValue(public val value: TopHitsResponseWithAnalytics) : GetTopHitsResponse
30+
31+
@Serializable
32+
@JvmInline
33+
public value class TopHitsResponseWithRevenueAnalyticsValue(public val value: TopHitsResponseWithRevenueAnalytics) : GetTopHitsResponse
2234

2335
public companion object {
36+
37+
public fun of(value: TopHitsResponse): GetTopHitsResponse {
38+
return TopHitsResponseValue(value)
39+
}
40+
public fun of(value: TopHitsResponseWithAnalytics): GetTopHitsResponse {
41+
return TopHitsResponseWithAnalyticsValue(value)
42+
}
43+
public fun of(value: TopHitsResponseWithRevenueAnalytics): GetTopHitsResponse {
44+
return TopHitsResponseWithRevenueAnalyticsValue(value)
45+
}
2446
}
2547
}
2648

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/analytics/GetTopSearchesResponse.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.serialization.builtins.*
88
import kotlinx.serialization.descriptors.*
99
import kotlinx.serialization.encoding.*
1010
import kotlinx.serialization.json.*
11+
import kotlin.jvm.JvmInline
1112

1213
/**
1314
* GetTopSearchesResponse
@@ -19,8 +20,29 @@ import kotlinx.serialization.json.*
1920
*/
2021
@Serializable(GetTopSearchesResponseSerializer::class)
2122
public sealed interface GetTopSearchesResponse {
23+
@Serializable
24+
@JvmInline
25+
public value class TopSearchesResponseValue(public val value: TopSearchesResponse) : GetTopSearchesResponse
26+
27+
@Serializable
28+
@JvmInline
29+
public value class TopSearchesResponseWithAnalyticsValue(public val value: TopSearchesResponseWithAnalytics) : GetTopSearchesResponse
30+
31+
@Serializable
32+
@JvmInline
33+
public value class TopSearchesResponseWithRevenueAnalyticsValue(public val value: TopSearchesResponseWithRevenueAnalytics) : GetTopSearchesResponse
2234

2335
public companion object {
36+
37+
public fun of(value: TopSearchesResponse): GetTopSearchesResponse {
38+
return TopSearchesResponseValue(value)
39+
}
40+
public fun of(value: TopSearchesResponseWithAnalytics): GetTopSearchesResponse {
41+
return TopSearchesResponseWithAnalyticsValue(value)
42+
}
43+
public fun of(value: TopSearchesResponseWithRevenueAnalytics): GetTopSearchesResponse {
44+
return TopSearchesResponseWithRevenueAnalyticsValue(value)
45+
}
2446
}
2547
}
2648

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/ingestion/AuthInput.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.serialization.builtins.*
88
import kotlinx.serialization.descriptors.*
99
import kotlinx.serialization.encoding.*
1010
import kotlinx.serialization.json.*
11+
import kotlin.jvm.JvmInline
1112

1213
/**
1314
* AuthInput
@@ -22,8 +23,50 @@ import kotlinx.serialization.json.*
2223
*/
2324
@Serializable(AuthInputSerializer::class)
2425
public sealed interface AuthInput {
26+
@Serializable
27+
@JvmInline
28+
public value class AuthOAuthValue(public val value: AuthOAuth) : AuthInput
29+
30+
@Serializable
31+
@JvmInline
32+
public value class AuthGoogleServiceAccountValue(public val value: AuthGoogleServiceAccount) : AuthInput
33+
34+
@Serializable
35+
@JvmInline
36+
public value class AuthBasicValue(public val value: AuthBasic) : AuthInput
37+
38+
@Serializable
39+
@JvmInline
40+
public value class AuthAPIKeyValue(public val value: AuthAPIKey) : AuthInput
41+
42+
@Serializable
43+
@JvmInline
44+
public value class AuthAlgoliaValue(public val value: AuthAlgolia) : AuthInput
45+
46+
@Serializable
47+
@JvmInline
48+
public value class AuthAlgoliaInsightsValue(public val value: AuthAlgoliaInsights) : AuthInput
2549

2650
public companion object {
51+
52+
public fun of(value: AuthOAuth): AuthInput {
53+
return AuthOAuthValue(value)
54+
}
55+
public fun of(value: AuthGoogleServiceAccount): AuthInput {
56+
return AuthGoogleServiceAccountValue(value)
57+
}
58+
public fun of(value: AuthBasic): AuthInput {
59+
return AuthBasicValue(value)
60+
}
61+
public fun of(value: AuthAPIKey): AuthInput {
62+
return AuthAPIKeyValue(value)
63+
}
64+
public fun of(value: AuthAlgolia): AuthInput {
65+
return AuthAlgoliaValue(value)
66+
}
67+
public fun of(value: AuthAlgoliaInsights): AuthInput {
68+
return AuthAlgoliaInsightsValue(value)
69+
}
2770
}
2871
}
2972

0 commit comments

Comments
 (0)