Skip to content

Commit bc7b312

Browse files
algolia-botkai687millotp
committed
fix(specs): built-in ops accept also int (#3450) (generated) [skip ci]
Co-authored-by: Kai Welke <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent e982ddf commit bc7b312

File tree

70 files changed

+1438
-168
lines changed

Some content is hidden

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

70 files changed

+1438
-168
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperation.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@ public BuiltInOperation() { }
3131
/// Initializes a new instance of the BuiltInOperation class.
3232
/// </summary>
3333
/// <param name="operation">operation (required).</param>
34-
/// <param name="value">Value that corresponds to the operation, for example an &#x60;Increment&#x60; or &#x60;Decrement&#x60; step, or an &#x60;Add&#x60; or &#x60;Remove&#x60; value. (required).</param>
35-
public BuiltInOperation(BuiltInOperationType? operation, string value)
34+
/// <param name="value">value (required).</param>
35+
public BuiltInOperation(BuiltInOperationType? operation, BuiltInOperationValue value)
3636
{
3737
Operation = operation;
3838
Value = value ?? throw new ArgumentNullException(nameof(value));
3939
}
4040

4141
/// <summary>
42-
/// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value.
42+
/// Gets or Sets Value
4343
/// </summary>
44-
/// <value>Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value.</value>
4544
[JsonPropertyName("value")]
46-
public string Value { get; set; }
45+
public BuiltInOperationValue Value { get; set; }
4746

4847
/// <summary>
4948
/// Returns the string presentation of the object
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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.Text;
6+
using System.Linq;
7+
using System.Text.Json.Serialization;
8+
using System.Collections.Generic;
9+
using Algolia.Search.Serializer;
10+
using System.Text.Json;
11+
using System.IO;
12+
using System.Reflection;
13+
using Algolia.Search.Models.Common;
14+
15+
namespace Algolia.Search.Models.Search;
16+
17+
/// <summary>
18+
/// BuiltInOperationValue
19+
/// </summary>
20+
[JsonConverter(typeof(BuiltInOperationValueJsonConverter))]
21+
public partial class BuiltInOperationValue : AbstractSchema
22+
{
23+
/// <summary>
24+
/// Initializes a new instance of the BuiltInOperationValue class
25+
/// with a string
26+
/// </summary>
27+
/// <param name="actualInstance">An instance of string.</param>
28+
public BuiltInOperationValue(string actualInstance)
29+
{
30+
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
31+
}
32+
33+
/// <summary>
34+
/// Initializes a new instance of the BuiltInOperationValue class
35+
/// with a int
36+
/// </summary>
37+
/// <param name="actualInstance">An instance of int.</param>
38+
public BuiltInOperationValue(int actualInstance)
39+
{
40+
ActualInstance = actualInstance;
41+
}
42+
43+
44+
/// <summary>
45+
/// Gets or Sets ActualInstance
46+
/// </summary>
47+
public sealed override object ActualInstance { get; set; }
48+
49+
/// <summary>
50+
/// Get the actual instance of `string`. If the actual instance is not `string`,
51+
/// the InvalidClassException will be thrown
52+
/// </summary>
53+
/// <returns>An instance of string</returns>
54+
public string AsString()
55+
{
56+
return (string)ActualInstance;
57+
}
58+
59+
/// <summary>
60+
/// Get the actual instance of `int`. If the actual instance is not `int`,
61+
/// the InvalidClassException will be thrown
62+
/// </summary>
63+
/// <returns>An instance of int</returns>
64+
public int AsInt()
65+
{
66+
return (int)ActualInstance;
67+
}
68+
69+
70+
/// <summary>
71+
/// Check if the actual instance is of `string` type.
72+
/// </summary>
73+
/// <returns>Whether or not the instance is the type</returns>
74+
public bool IsString()
75+
{
76+
return ActualInstance.GetType() == typeof(string);
77+
}
78+
79+
/// <summary>
80+
/// Check if the actual instance is of `int` type.
81+
/// </summary>
82+
/// <returns>Whether or not the instance is the type</returns>
83+
public bool IsInt()
84+
{
85+
return ActualInstance.GetType() == typeof(int);
86+
}
87+
88+
/// <summary>
89+
/// Returns the string presentation of the object
90+
/// </summary>
91+
/// <returns>String presentation of the object</returns>
92+
public override string ToString()
93+
{
94+
var sb = new StringBuilder();
95+
sb.Append("class BuiltInOperationValue {\n");
96+
sb.Append(" ActualInstance: ").Append(ActualInstance).Append("\n");
97+
sb.Append("}\n");
98+
return sb.ToString();
99+
}
100+
101+
/// <summary>
102+
/// Returns the JSON string presentation of the object
103+
/// </summary>
104+
/// <returns>JSON string presentation of the object</returns>
105+
public override string ToJson()
106+
{
107+
return JsonSerializer.Serialize(ActualInstance, JsonConfig.Options);
108+
}
109+
110+
/// <summary>
111+
/// Returns true if objects are equal
112+
/// </summary>
113+
/// <param name="obj">Object to be compared</param>
114+
/// <returns>Boolean</returns>
115+
public override bool Equals(object obj)
116+
{
117+
if (obj is not BuiltInOperationValue input)
118+
{
119+
return false;
120+
}
121+
122+
return ActualInstance.Equals(input.ActualInstance);
123+
}
124+
125+
/// <summary>
126+
/// Gets the hash code
127+
/// </summary>
128+
/// <returns>Hash code</returns>
129+
public override int GetHashCode()
130+
{
131+
unchecked // Overflow is fine, just wrap
132+
{
133+
int hashCode = 41;
134+
if (ActualInstance != null)
135+
hashCode = hashCode * 59 + ActualInstance.GetHashCode();
136+
return hashCode;
137+
}
138+
}
139+
}
140+
141+
142+
143+
144+
145+
/// <summary>
146+
/// Custom JSON converter for BuiltInOperationValue
147+
/// </summary>
148+
public class BuiltInOperationValueJsonConverter : JsonConverter<BuiltInOperationValue>
149+
{
150+
151+
/// <summary>
152+
/// Check if the object can be converted
153+
/// </summary>
154+
/// <param name="objectType">Object type</param>
155+
/// <returns>True if the object can be converted</returns>
156+
public override bool CanConvert(Type objectType)
157+
{
158+
return objectType == typeof(BuiltInOperationValue);
159+
}
160+
161+
/// <summary>
162+
/// To convert a JSON string into an object
163+
/// </summary>
164+
/// <param name="reader">JSON reader</param>
165+
/// <param name="typeToConvert">Object type</param>
166+
/// <param name="options">Serializer options</param>
167+
/// <returns>The object converted from the JSON string</returns>
168+
public override BuiltInOperationValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
169+
{
170+
var jsonDocument = JsonDocument.ParseValue(ref reader);
171+
var root = jsonDocument.RootElement;
172+
if (root.ValueKind == JsonValueKind.String)
173+
{
174+
try
175+
{
176+
return new BuiltInOperationValue(jsonDocument.Deserialize<string>(JsonConfig.Options));
177+
}
178+
catch (Exception exception)
179+
{
180+
// deserialization failed, try the next one
181+
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into string: {exception}");
182+
}
183+
}
184+
if (root.ValueKind == JsonValueKind.Number)
185+
{
186+
try
187+
{
188+
return new BuiltInOperationValue(jsonDocument.Deserialize<int>(JsonConfig.Options));
189+
}
190+
catch (Exception exception)
191+
{
192+
// deserialization failed, try the next one
193+
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into int: {exception}");
194+
}
195+
}
196+
throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined.");
197+
}
198+
199+
/// <summary>
200+
/// To write the JSON string
201+
/// </summary>
202+
/// <param name="writer">JSON writer</param>
203+
/// <param name="value">BuiltInOperationValue to be converted into a JSON string</param>
204+
/// <param name="options">JSON Serializer options</param>
205+
public override void Write(Utf8JsonWriter writer, BuiltInOperationValue value, JsonSerializerOptions options)
206+
{
207+
writer.WriteRawValue(value.ToJson());
208+
}
209+
}
210+

clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ final class BuiltInOperation {
1717
@JsonKey(name: r'_operation')
1818
final BuiltInOperationType operation;
1919

20-
/// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value.
20+
/// One of types:
21+
/// - [String]
22+
/// - [int]
2123
@JsonKey(name: r'value')
22-
final String value;
24+
final dynamic value;
2325

2426
@override
2527
bool operator ==(Object other) =>

clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.g.dart

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

clients/algoliasearch-client-go/algolia/search/model_built_in_operation.go

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

0 commit comments

Comments
 (0)