-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(specs): built-in ops accept also int (generated)
algolia/api-clients-automation#3450 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Kai Welke <kai.welke@algolia.com> Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
- Loading branch information
1 parent
3e03ebd
commit c83d8bd
Showing
2 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
// | ||
// 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. | ||
// | ||
using System; | ||
using System.Text; | ||
using System.Linq; | ||
using System.Text.Json.Serialization; | ||
using System.Collections.Generic; | ||
using Algolia.Search.Serializer; | ||
using System.Text.Json; | ||
using System.IO; | ||
using System.Reflection; | ||
using Algolia.Search.Models.Common; | ||
|
||
namespace Algolia.Search.Models.Search; | ||
|
||
/// <summary> | ||
/// BuiltInOperationValue | ||
/// </summary> | ||
[JsonConverter(typeof(BuiltInOperationValueJsonConverter))] | ||
public partial class BuiltInOperationValue : AbstractSchema | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the BuiltInOperationValue class | ||
/// with a string | ||
/// </summary> | ||
/// <param name="actualInstance">An instance of string.</param> | ||
public BuiltInOperationValue(string actualInstance) | ||
{ | ||
ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null."); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the BuiltInOperationValue class | ||
/// with a int | ||
/// </summary> | ||
/// <param name="actualInstance">An instance of int.</param> | ||
public BuiltInOperationValue(int actualInstance) | ||
{ | ||
ActualInstance = actualInstance; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Gets or Sets ActualInstance | ||
/// </summary> | ||
public sealed override object ActualInstance { get; set; } | ||
|
||
/// <summary> | ||
/// Get the actual instance of `string`. If the actual instance is not `string`, | ||
/// the InvalidClassException will be thrown | ||
/// </summary> | ||
/// <returns>An instance of string</returns> | ||
public string AsString() | ||
{ | ||
return (string)ActualInstance; | ||
} | ||
|
||
/// <summary> | ||
/// Get the actual instance of `int`. If the actual instance is not `int`, | ||
/// the InvalidClassException will be thrown | ||
/// </summary> | ||
/// <returns>An instance of int</returns> | ||
public int AsInt() | ||
{ | ||
return (int)ActualInstance; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Check if the actual instance is of `string` type. | ||
/// </summary> | ||
/// <returns>Whether or not the instance is the type</returns> | ||
public bool IsString() | ||
{ | ||
return ActualInstance.GetType() == typeof(string); | ||
} | ||
|
||
/// <summary> | ||
/// Check if the actual instance is of `int` type. | ||
/// </summary> | ||
/// <returns>Whether or not the instance is the type</returns> | ||
public bool IsInt() | ||
{ | ||
return ActualInstance.GetType() == typeof(int); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the string presentation of the object | ||
/// </summary> | ||
/// <returns>String presentation of the object</returns> | ||
public override string ToString() | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append("class BuiltInOperationValue {\n"); | ||
sb.Append(" ActualInstance: ").Append(ActualInstance).Append("\n"); | ||
sb.Append("}\n"); | ||
return sb.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the JSON string presentation of the object | ||
/// </summary> | ||
/// <returns>JSON string presentation of the object</returns> | ||
public override string ToJson() | ||
{ | ||
return JsonSerializer.Serialize(ActualInstance, JsonConfig.Options); | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if objects are equal | ||
/// </summary> | ||
/// <param name="obj">Object to be compared</param> | ||
/// <returns>Boolean</returns> | ||
public override bool Equals(object obj) | ||
{ | ||
if (obj is not BuiltInOperationValue input) | ||
{ | ||
return false; | ||
} | ||
|
||
return ActualInstance.Equals(input.ActualInstance); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the hash code | ||
/// </summary> | ||
/// <returns>Hash code</returns> | ||
public override int GetHashCode() | ||
{ | ||
unchecked // Overflow is fine, just wrap | ||
{ | ||
int hashCode = 41; | ||
if (ActualInstance != null) | ||
hashCode = hashCode * 59 + ActualInstance.GetHashCode(); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
/// <summary> | ||
/// Custom JSON converter for BuiltInOperationValue | ||
/// </summary> | ||
public class BuiltInOperationValueJsonConverter : JsonConverter<BuiltInOperationValue> | ||
{ | ||
|
||
/// <summary> | ||
/// Check if the object can be converted | ||
/// </summary> | ||
/// <param name="objectType">Object type</param> | ||
/// <returns>True if the object can be converted</returns> | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(BuiltInOperationValue); | ||
} | ||
|
||
/// <summary> | ||
/// To convert a JSON string into an object | ||
/// </summary> | ||
/// <param name="reader">JSON reader</param> | ||
/// <param name="typeToConvert">Object type</param> | ||
/// <param name="options">Serializer options</param> | ||
/// <returns>The object converted from the JSON string</returns> | ||
public override BuiltInOperationValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var jsonDocument = JsonDocument.ParseValue(ref reader); | ||
var root = jsonDocument.RootElement; | ||
if (root.ValueKind == JsonValueKind.String) | ||
{ | ||
try | ||
{ | ||
return new BuiltInOperationValue(jsonDocument.Deserialize<string>(JsonConfig.Options)); | ||
} | ||
catch (Exception exception) | ||
{ | ||
// deserialization failed, try the next one | ||
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into string: {exception}"); | ||
} | ||
} | ||
if (root.ValueKind == JsonValueKind.Number) | ||
{ | ||
try | ||
{ | ||
return new BuiltInOperationValue(jsonDocument.Deserialize<int>(JsonConfig.Options)); | ||
} | ||
catch (Exception exception) | ||
{ | ||
// deserialization failed, try the next one | ||
System.Diagnostics.Debug.WriteLine($"Failed to deserialize into int: {exception}"); | ||
} | ||
} | ||
throw new InvalidDataException($"The JSON string cannot be deserialized into any schema defined."); | ||
} | ||
|
||
/// <summary> | ||
/// To write the JSON string | ||
/// </summary> | ||
/// <param name="writer">JSON writer</param> | ||
/// <param name="value">BuiltInOperationValue to be converted into a JSON string</param> | ||
/// <param name="options">JSON Serializer options</param> | ||
public override void Write(Utf8JsonWriter writer, BuiltInOperationValue value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteRawValue(value.ToJson()); | ||
} | ||
} | ||
|