From bc7b312c6c1ed7d4d177e631bae044258cd7d09c Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Wed, 31 Jul 2024 09:45:56 +0000 Subject: [PATCH] fix(specs): built-in ops accept also int (#3450) (generated) [skip ci] Co-authored-by: Kai Welke Co-authored-by: Pierre Millot --- .../Models/Search/BuiltInOperation.cs | 9 +- .../Models/Search/BuiltInOperationValue.cs | 210 ++++++++++++++++++ .../lib/src/model/built_in_operation.dart | 6 +- .../lib/src/model/built_in_operation.g.dart | 21 +- .../search/model_built_in_operation.go | 17 +- .../search/model_built_in_operation_value.go | 96 ++++++++ .../model/search/BuiltInOperation.java | 11 +- .../model/search/BuiltInOperationValue.java | 109 +++++++++ .../client-search/model/builtInOperation.ts | 6 +- .../model/builtInOperationValue.ts | 3 + .../packages/client-search/model/index.ts | 1 + .../client/model/search/BuiltInOperation.kt | 5 +- .../model/search/BuiltInOperationValue.kt | 49 ++++ .../lib/Model/Search/AttributeToUpdate.php | 6 +- .../lib/Model/Search/BuiltInOperation.php | 6 +- .../Model/Search/BuiltInOperationValue.php | 191 ++++++++++++++++ .../search/models/built_in_operation.py | 18 +- .../search/models/built_in_operation_value.py | 108 +++++++++ .../models/search/built_in_operation.rb | 3 +- .../models/search/built_in_operation_value.rb | 105 +++++++++ .../search/BuiltInOperation.scala | 6 +- .../search/BuiltInOperationValue.scala | 73 ++++++ .../algoliasearch/search/JsonSupport.scala | 1 + .../Search/Models/BuiltInOperation.swift | 6 +- .../Search/Models/BuiltInOperationValue.swift | 51 +++++ snippets/csharp/src/Search.cs | 4 +- snippets/dart/lib/search.dart | 2 +- snippets/go/src/search.go | 4 +- snippets/guides/search-snippets.json | 12 +- .../src/test/java/com/algolia/Search.java | 4 +- snippets/javascript/src/search.ts | 2 +- .../kotlin/com/algolia/snippets/Search.kt | 2 +- snippets/php/src/Search.php | 2 +- snippets/python/search.py | 2 +- snippets/ruby/search.rb | 2 +- snippets/scala/src/main/scala/Search.scala | 4 +- snippets/swift/Sources/Search.swift | 7 +- specs/bundled/search.doc.yml | 28 ++- specs/bundled/search.yml | 13 +- .../csharp/src/generated/e2e/Insights.test.cs | 4 +- .../src/generated/requests/Insights.test.cs | 6 +- .../src/generated/requests/Search.test.cs | 35 ++- .../dart/test/requests/insights_test.dart | 6 +- .../dart/test/requests/search_test.dart | 30 ++- tests/output/go/tests/e2e/insights_test.go | 4 +- .../output/go/tests/requests/insights_test.go | 6 +- tests/output/go/tests/requests/search_test.go | 17 +- .../java/com/algolia/e2e/Insights.test.java | 4 +- .../com/algolia/requests/Insights.test.java | 8 +- .../com/algolia/requests/Search.test.java | 22 +- .../javascript/src/e2e/insights.test.ts | 4 +- .../javascript/src/requests/insights.test.ts | 8 +- .../javascript/src/requests/search.test.ts | 19 +- .../com/algolia/requests/InsightsTest.kt | 6 +- .../kotlin/com/algolia/requests/SearchTest.kt | 27 ++- tests/output/php/src/e2e/InsightsTest.php | 4 +- .../output/php/src/requests/InsightsTest.php | 6 +- tests/output/php/src/requests/SearchTest.php | 24 +- .../output/python/tests/e2e/insights_test.py | 8 +- .../python/tests/requests/insights_test.py | 6 +- .../python/tests/requests/search_test.py | 25 ++- tests/output/ruby/test/e2e/insights_test.rb | 8 +- .../ruby/test/requests/insights_test.rb | 6 +- .../output/ruby/test/requests/search_test.rb | 17 +- .../algoliasearch/e2e/InsightsTest.scala | 4 +- .../algoliasearch/requests/InsightsTest.scala | 6 +- .../algoliasearch/requests/SearchTest.scala | 27 ++- .../swift/Tests/e2e/InsightsTests.swift | 4 +- .../swift/Tests/requests/InsightsTests.swift | 6 +- .../swift/Tests/requests/SearchTests.swift | 44 +++- 70 files changed, 1438 insertions(+), 168 deletions(-) create mode 100644 clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperationValue.cs create mode 100644 clients/algoliasearch-client-go/algolia/search/model_built_in_operation_value.go create mode 100644 clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperationValue.java create mode 100644 clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperationValue.ts create mode 100644 clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperationValue.kt create mode 100644 clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperationValue.php create mode 100644 clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation_value.py create mode 100644 clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation_value.rb create mode 100644 clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperationValue.scala create mode 100644 clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperationValue.swift diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperation.cs b/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperation.cs index 0b2d1c42bc..8ace1687ca 100644 --- a/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperation.cs +++ b/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperation.cs @@ -31,19 +31,18 @@ public BuiltInOperation() { } /// Initializes a new instance of the BuiltInOperation class. /// /// operation (required). - /// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. (required). - public BuiltInOperation(BuiltInOperationType? operation, string value) + /// value (required). + public BuiltInOperation(BuiltInOperationType? operation, BuiltInOperationValue value) { Operation = operation; Value = value ?? throw new ArgumentNullException(nameof(value)); } /// - /// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. + /// Gets or Sets Value /// - /// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. [JsonPropertyName("value")] - public string Value { get; set; } + public BuiltInOperationValue Value { get; set; } /// /// Returns the string presentation of the object diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperationValue.cs b/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperationValue.cs new file mode 100644 index 0000000000..ee02bb24f7 --- /dev/null +++ b/clients/algoliasearch-client-csharp/algoliasearch/Models/Search/BuiltInOperationValue.cs @@ -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; + +/// +/// BuiltInOperationValue +/// +[JsonConverter(typeof(BuiltInOperationValueJsonConverter))] +public partial class BuiltInOperationValue : AbstractSchema +{ + /// + /// Initializes a new instance of the BuiltInOperationValue class + /// with a string + /// + /// An instance of string. + public BuiltInOperationValue(string actualInstance) + { + ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null."); + } + + /// + /// Initializes a new instance of the BuiltInOperationValue class + /// with a int + /// + /// An instance of int. + public BuiltInOperationValue(int actualInstance) + { + ActualInstance = actualInstance; + } + + + /// + /// Gets or Sets ActualInstance + /// + public sealed override object ActualInstance { get; set; } + + /// + /// Get the actual instance of `string`. If the actual instance is not `string`, + /// the InvalidClassException will be thrown + /// + /// An instance of string + public string AsString() + { + return (string)ActualInstance; + } + + /// + /// Get the actual instance of `int`. If the actual instance is not `int`, + /// the InvalidClassException will be thrown + /// + /// An instance of int + public int AsInt() + { + return (int)ActualInstance; + } + + + /// + /// Check if the actual instance is of `string` type. + /// + /// Whether or not the instance is the type + public bool IsString() + { + return ActualInstance.GetType() == typeof(string); + } + + /// + /// Check if the actual instance is of `int` type. + /// + /// Whether or not the instance is the type + public bool IsInt() + { + return ActualInstance.GetType() == typeof(int); + } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + 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(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public override string ToJson() + { + return JsonSerializer.Serialize(ActualInstance, JsonConfig.Options); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is not BuiltInOperationValue input) + { + return false; + } + + return ActualInstance.Equals(input.ActualInstance); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (ActualInstance != null) + hashCode = hashCode * 59 + ActualInstance.GetHashCode(); + return hashCode; + } + } +} + + + + + +/// +/// Custom JSON converter for BuiltInOperationValue +/// +public class BuiltInOperationValueJsonConverter : JsonConverter +{ + + /// + /// Check if the object can be converted + /// + /// Object type + /// True if the object can be converted + public override bool CanConvert(Type objectType) + { + return objectType == typeof(BuiltInOperationValue); + } + + /// + /// To convert a JSON string into an object + /// + /// JSON reader + /// Object type + /// Serializer options + /// The object converted from the JSON string + 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(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(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."); + } + + /// + /// To write the JSON string + /// + /// JSON writer + /// BuiltInOperationValue to be converted into a JSON string + /// JSON Serializer options + public override void Write(Utf8JsonWriter writer, BuiltInOperationValue value, JsonSerializerOptions options) + { + writer.WriteRawValue(value.ToJson()); + } +} + diff --git a/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.dart b/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.dart index 0104c19fca..0ca74ad78b 100644 --- a/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.dart +++ b/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.dart @@ -17,9 +17,11 @@ final class BuiltInOperation { @JsonKey(name: r'_operation') final BuiltInOperationType operation; - /// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. + /// One of types: + /// - [String] + /// - [int] @JsonKey(name: r'value') - final String value; + final dynamic value; @override bool operator ==(Object other) => diff --git a/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.g.dart b/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.g.dart index f847c6c60a..2b2926391b 100644 --- a/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.g.dart +++ b/clients/algoliasearch-client-dart/packages/client_search/lib/src/model/built_in_operation.g.dart @@ -14,18 +14,27 @@ BuiltInOperation _$BuiltInOperationFromJson(Map json) => final val = BuiltInOperation( operation: $checkedConvert('_operation', (v) => $enumDecode(_$BuiltInOperationTypeEnumMap, v)), - value: $checkedConvert('value', (v) => v as String), + value: $checkedConvert('value', (v) => v), ); return val; }, fieldKeyMap: const {'operation': '_operation'}, ); -Map _$BuiltInOperationToJson(BuiltInOperation instance) => - { - '_operation': instance.operation.toJson(), - 'value': instance.value, - }; +Map _$BuiltInOperationToJson(BuiltInOperation instance) { + final val = { + '_operation': instance.operation.toJson(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('value', instance.value); + return val; +} const _$BuiltInOperationTypeEnumMap = { BuiltInOperationType.increment: 'Increment', diff --git a/clients/algoliasearch-client-go/algolia/search/model_built_in_operation.go b/clients/algoliasearch-client-go/algolia/search/model_built_in_operation.go index 5c95646d8c..85c3479d9a 100644 --- a/clients/algoliasearch-client-go/algolia/search/model_built_in_operation.go +++ b/clients/algoliasearch-client-go/algolia/search/model_built_in_operation.go @@ -8,16 +8,15 @@ import ( // BuiltInOperation Update to perform on the attribute. type BuiltInOperation struct { - Operation BuiltInOperationType `json:"_operation"` - // Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. - Value string `json:"value"` + Operation BuiltInOperationType `json:"_operation"` + Value BuiltInOperationValue `json:"value"` } // NewBuiltInOperation instantiates a new BuiltInOperation object // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed. -func NewBuiltInOperation(operation BuiltInOperationType, value string) *BuiltInOperation { +func NewBuiltInOperation(operation BuiltInOperationType, value BuiltInOperationValue) *BuiltInOperation { this := &BuiltInOperation{} this.Operation = operation this.Value = value @@ -55,9 +54,9 @@ func (o *BuiltInOperation) SetOperation(v BuiltInOperationType) *BuiltInOperatio } // GetValue returns the Value field value. -func (o *BuiltInOperation) GetValue() string { +func (o *BuiltInOperation) GetValue() BuiltInOperationValue { if o == nil { - var ret string + var ret BuiltInOperationValue return ret } @@ -66,7 +65,7 @@ func (o *BuiltInOperation) GetValue() string { // GetValueOk returns a tuple with the Value field value // and a boolean to check if the value has been set. -func (o *BuiltInOperation) GetValueOk() (*string, bool) { +func (o *BuiltInOperation) GetValueOk() (*BuiltInOperationValue, bool) { if o == nil { return nil, false } @@ -74,8 +73,8 @@ func (o *BuiltInOperation) GetValueOk() (*string, bool) { } // SetValue sets field value. -func (o *BuiltInOperation) SetValue(v string) *BuiltInOperation { - o.Value = v +func (o *BuiltInOperation) SetValue(v *BuiltInOperationValue) *BuiltInOperation { + o.Value = *v return o } diff --git a/clients/algoliasearch-client-go/algolia/search/model_built_in_operation_value.go b/clients/algoliasearch-client-go/algolia/search/model_built_in_operation_value.go new file mode 100644 index 0000000000..b26a167922 --- /dev/null +++ b/clients/algoliasearch-client-go/algolia/search/model_built_in_operation_value.go @@ -0,0 +1,96 @@ +// 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. +package search + +import ( + "encoding/json" + "fmt" +) + +// BuiltInOperationValue - struct for BuiltInOperationValue. +type BuiltInOperationValue struct { + Int32 *int32 + String *string +} + +// stringAsBuiltInOperationValue is a convenience function that returns string wrapped in BuiltInOperationValue. +func StringAsBuiltInOperationValue(v string) *BuiltInOperationValue { + return &BuiltInOperationValue{ + String: &v, + } +} + +// int32AsBuiltInOperationValue is a convenience function that returns int32 wrapped in BuiltInOperationValue. +func Int32AsBuiltInOperationValue(v int32) *BuiltInOperationValue { + return &BuiltInOperationValue{ + Int32: &v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct. +func (dst *BuiltInOperationValue) UnmarshalJSON(data []byte) error { + var err error + // try to unmarshal data into Int32 + err = newStrictDecoder(data).Decode(&dst.Int32) + if err == nil && validateStruct(dst.Int32) == nil { + jsonInt32, _ := json.Marshal(dst.Int32) + if string(jsonInt32) == "{}" { // empty struct + dst.Int32 = nil + } else { + return nil + } + } else { + dst.Int32 = nil + } + + // try to unmarshal data into String + err = newStrictDecoder(data).Decode(&dst.String) + if err == nil && validateStruct(dst.String) == nil { + jsonString, _ := json.Marshal(dst.String) + if string(jsonString) == "{}" { // empty struct + dst.String = nil + } else { + return nil + } + } else { + dst.String = nil + } + + return fmt.Errorf("Data failed to match schemas in oneOf(BuiltInOperationValue)") +} + +// Marshal data from the first non-nil pointers in the struct to JSON. +func (src BuiltInOperationValue) MarshalJSON() ([]byte, error) { + if src.Int32 != nil { + serialized, err := json.Marshal(&src.Int32) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal one of Int32 of BuiltInOperationValue: %w", err) + } + + return serialized, nil + } + + if src.String != nil { + serialized, err := json.Marshal(&src.String) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal one of String of BuiltInOperationValue: %w", err) + } + + return serialized, nil + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance. +func (obj BuiltInOperationValue) GetActualInstance() any { + if obj.Int32 != nil { + return *obj.Int32 + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperation.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperation.java index f259266878..80a34af4a5 100644 --- a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperation.java +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperation.java @@ -15,7 +15,7 @@ public class BuiltInOperation implements AttributeToUpdate { private BuiltInOperationType operation; @JsonProperty("value") - private String value; + private BuiltInOperationValue value; public BuiltInOperation setOperation(BuiltInOperationType operation) { this.operation = operation; @@ -28,17 +28,14 @@ public BuiltInOperationType getOperation() { return operation; } - public BuiltInOperation setValue(String value) { + public BuiltInOperation setValue(BuiltInOperationValue value) { this.value = value; return this; } - /** - * Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an - * `Add` or `Remove` value. - */ + /** Get value */ @javax.annotation.Nonnull - public String getValue() { + public BuiltInOperationValue getValue() { return value; } diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperationValue.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperationValue.java new file mode 100644 index 0000000000..3928f0257f --- /dev/null +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/search/BuiltInOperationValue.java @@ -0,0 +1,109 @@ +// 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. + +package com.algolia.model.search; + +import com.algolia.exceptions.AlgoliaRuntimeException; +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.annotation.*; +import java.io.IOException; +import java.util.logging.Logger; + +/** BuiltInOperationValue */ +@JsonDeserialize(using = BuiltInOperationValue.Deserializer.class) +public interface BuiltInOperationValue { + // BuiltInOperationValue as String wrapper. + static BuiltInOperationValue of(String value) { + return new StringWrapper(value); + } + + // BuiltInOperationValue as Integer wrapper. + static BuiltInOperationValue of(Integer value) { + return new IntegerWrapper(value); + } + + // BuiltInOperationValue as String wrapper. + @JsonSerialize(using = StringWrapper.Serializer.class) + class StringWrapper implements BuiltInOperationValue { + + private final String value; + + StringWrapper(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + static class Serializer extends JsonSerializer { + + @Override + public void serialize(StringWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeObject(value.getValue()); + } + } + } + + // BuiltInOperationValue as Integer wrapper. + @JsonSerialize(using = IntegerWrapper.Serializer.class) + class IntegerWrapper implements BuiltInOperationValue { + + private final Integer value; + + IntegerWrapper(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } + + static class Serializer extends JsonSerializer { + + @Override + public void serialize(IntegerWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeObject(value.getValue()); + } + } + } + + class Deserializer extends JsonDeserializer { + + private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName()); + + @Override + public BuiltInOperationValue deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { + JsonNode tree = jp.readValueAsTree(); + // deserialize String + if (tree.isTextual()) { + try (JsonParser parser = tree.traverse(jp.getCodec())) { + String value = parser.readValueAs(String.class); + return new BuiltInOperationValue.StringWrapper(value); + } catch (Exception e) { + // deserialization failed, continue + LOGGER.finest("Failed to deserialize oneOf String (error: " + e.getMessage() + ") (type: String)"); + } + } + // deserialize Integer + if (tree.isInt()) { + try (JsonParser parser = tree.traverse(jp.getCodec())) { + Integer value = parser.readValueAs(Integer.class); + return new BuiltInOperationValue.IntegerWrapper(value); + } catch (Exception e) { + // deserialization failed, continue + LOGGER.finest("Failed to deserialize oneOf Integer (error: " + e.getMessage() + ") (type: Integer)"); + } + } + throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public BuiltInOperationValue getNullValue(DeserializationContext ctxt) throws JsonMappingException { + throw new JsonMappingException(ctxt.getParser(), "BuiltInOperationValue cannot be null"); + } + } +} diff --git a/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperation.ts b/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperation.ts index d3df17410b..a0e14ee196 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperation.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperation.ts @@ -1,6 +1,7 @@ // 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. import type { BuiltInOperationType } from './builtInOperationType'; +import type { BuiltInOperationValue } from './builtInOperationValue'; /** * Update to perform on the attribute. @@ -8,8 +9,5 @@ import type { BuiltInOperationType } from './builtInOperationType'; export type BuiltInOperation = { _operation: BuiltInOperationType; - /** - * Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. - */ - value: string; + value: BuiltInOperationValue; }; diff --git a/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperationValue.ts b/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperationValue.ts new file mode 100644 index 0000000000..8d8710eceb --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-search/model/builtInOperationValue.ts @@ -0,0 +1,3 @@ +// 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. + +export type BuiltInOperationValue = number | string; diff --git a/clients/algoliasearch-client-javascript/packages/client-search/model/index.ts b/clients/algoliasearch-client-javascript/packages/client-search/model/index.ts index fd7c2f1a56..3f77a760e7 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/model/index.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/model/index.ts @@ -33,6 +33,7 @@ export * from './browseParamsObject'; export * from './browseResponse'; export * from './builtInOperation'; export * from './builtInOperationType'; +export * from './builtInOperationValue'; export * from './condition'; export * from './consequence'; export * from './consequenceHide'; diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperation.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperation.kt index 35ac92852a..706e75628a 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperation.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperation.kt @@ -8,13 +8,12 @@ import kotlinx.serialization.json.* * Update to perform on the attribute. * * @param operation - * @param `value` Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. + * @param `value` */ @Serializable public data class BuiltInOperation( @SerialName(value = "_operation") val operation: BuiltInOperationType, - /** Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. */ - @SerialName(value = "value") val `value`: String, + @SerialName(value = "value") val `value`: BuiltInOperationValue, ) : AttributeToUpdate diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperationValue.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperationValue.kt new file mode 100644 index 0000000000..64ec643da0 --- /dev/null +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/search/BuiltInOperationValue.kt @@ -0,0 +1,49 @@ +/** 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. */ +package com.algolia.client.model.search + +import com.algolia.client.exception.AlgoliaClientException +import com.algolia.client.extensions.internal.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* +import kotlinx.serialization.json.* +import kotlin.jvm.JvmInline + +/** + * BuiltInOperationValue + * + * Implementations: + * - [Int] - *[BuiltInOperationValue.of]* + * - [String] - *[BuiltInOperationValue.of]* + */ +@Serializable(BuiltInOperationValueSerializer::class) +public sealed interface BuiltInOperationValue { + @Serializable + @JvmInline + public value class StringValue(public val value: String) : BuiltInOperationValue + + @Serializable + @JvmInline + public value class IntValue(public val value: Int) : BuiltInOperationValue + + public companion object { + + public fun of(value: String): BuiltInOperationValue { + return StringValue(value) + } + public fun of(value: Int): BuiltInOperationValue { + return IntValue(value) + } + } +} + +internal class BuiltInOperationValueSerializer : JsonContentPolymorphicSerializer(BuiltInOperationValue::class) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy { + return when { + element.isString -> BuiltInOperationValue.StringValue.serializer() + element.isInt -> BuiltInOperationValue.IntValue.serializer() + else -> throw AlgoliaClientException("Failed to deserialize json element: $element") + } + } +} diff --git a/clients/algoliasearch-client-php/lib/Model/Search/AttributeToUpdate.php b/clients/algoliasearch-client-php/lib/Model/Search/AttributeToUpdate.php index 9630ef7a75..4fdaedf54a 100644 --- a/clients/algoliasearch-client-php/lib/Model/Search/AttributeToUpdate.php +++ b/clients/algoliasearch-client-php/lib/Model/Search/AttributeToUpdate.php @@ -20,7 +20,7 @@ class AttributeToUpdate extends AbstractModel implements ModelInterface, \ArrayA */ protected static $modelTypes = [ 'operation' => '\Algolia\AlgoliaSearch\Model\Search\BuiltInOperationType', - 'value' => 'string', + 'value' => '\Algolia\AlgoliaSearch\Model\Search\BuiltInOperationValue', ]; /** @@ -194,7 +194,7 @@ public function setOperation($operation) /** * Gets value. * - * @return string + * @return BuiltInOperationValue */ public function getValue() { @@ -204,7 +204,7 @@ public function getValue() /** * Sets value. * - * @param string $value value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value + * @param BuiltInOperationValue $value value * * @return self */ diff --git a/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperation.php b/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperation.php index 99221bf8ee..ca4404af31 100644 --- a/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperation.php +++ b/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperation.php @@ -22,7 +22,7 @@ class BuiltInOperation extends AbstractModel implements ModelInterface, \ArrayAc */ protected static $modelTypes = [ 'operation' => '\Algolia\AlgoliaSearch\Model\Search\BuiltInOperationType', - 'value' => 'string', + 'value' => '\Algolia\AlgoliaSearch\Model\Search\BuiltInOperationValue', ]; /** @@ -196,7 +196,7 @@ public function setOperation($operation) /** * Gets value. * - * @return string + * @return BuiltInOperationValue */ public function getValue() { @@ -206,7 +206,7 @@ public function getValue() /** * Sets value. * - * @param string $value value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value + * @param BuiltInOperationValue $value value * * @return self */ diff --git a/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperationValue.php b/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperationValue.php new file mode 100644 index 0000000000..c2f0347ad7 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Model/Search/BuiltInOperationValue.php @@ -0,0 +1,191 @@ +listInvalidProperties()); + } + + /** + * Returns true if offset exists. False otherwise. + * + * @param int $offset Offset + * + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param int $offset Offset + * + * @return null|mixed + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param null|int $offset Offset + * @param mixed $value Value to be set + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param int $offset Offset + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } +} diff --git a/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation.py b/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation.py index 2deb9b1699..8cabd050ad 100644 --- a/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation.py +++ b/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation.py @@ -9,9 +9,10 @@ from json import loads from typing import Any, Dict, Self -from pydantic import BaseModel, ConfigDict, Field, StrictStr +from pydantic import BaseModel, ConfigDict, Field from algoliasearch.search.models.built_in_operation_type import BuiltInOperationType +from algoliasearch.search.models.built_in_operation_value import BuiltInOperationValue class BuiltInOperation(BaseModel): @@ -20,9 +21,7 @@ class BuiltInOperation(BaseModel): """ operation: BuiltInOperationType = Field(alias="_operation") - value: StrictStr = Field( - description="Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value." - ) + value: BuiltInOperationValue model_config = ConfigDict( use_enum_values=True, populate_by_name=True, validate_assignment=True @@ -51,6 +50,8 @@ def to_dict(self) -> Dict[str, Any]: exclude={}, exclude_none=True, ) + if self.value: + _dict["value"] = self.value.to_dict() return _dict @classmethod @@ -63,6 +64,13 @@ def from_dict(cls, obj: Dict) -> Self: return cls.model_validate(obj) _obj = cls.model_validate( - {"_operation": obj.get("_operation"), "value": obj.get("value")} + { + "_operation": obj.get("_operation"), + "value": ( + BuiltInOperationValue.from_dict(obj.get("value")) + if obj.get("value") is not None + else None + ), + } ) return _obj diff --git a/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation_value.py b/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation_value.py new file mode 100644 index 0000000000..fa04889266 --- /dev/null +++ b/clients/algoliasearch-client-python/algoliasearch/search/models/built_in_operation_value.py @@ -0,0 +1,108 @@ +# coding: utf-8 + +""" +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. +""" + +from __future__ import annotations + +from json import dumps, loads +from typing import Dict, Optional, Self, Union + +from pydantic import ( + BaseModel, + Field, + StrictInt, + StrictStr, + ValidationError, + model_serializer, +) + + +class BuiltInOperationValue(BaseModel): + """ + BuiltInOperationValue + """ + + oneof_schema_1_validator: Optional[StrictStr] = Field( + default=None, + description="A string to append or remove for the `Add`, `Remove`, and `AddUnique` operations.", + ) + oneof_schema_2_validator: Optional[StrictInt] = Field( + default=None, + description="A number to add, remove, or append, depending on the operation.", + ) + actual_instance: Optional[Union[int, str]] = None + + def __init__(self, *args, **kwargs) -> None: + if args: + if len(args) > 1: + raise ValueError( + "If a position argument is used, only 1 is allowed to set `actual_instance`" + ) + if kwargs: + raise ValueError( + "If a position argument is used, keyword arguments cannot be used." + ) + super().__init__(actual_instance=args[0]) + else: + super().__init__(**kwargs) + + @model_serializer + def unwrap_actual_instance(self) -> Optional[Union[int, str]]: + """ + Unwraps the `actual_instance` when calling the `to_json` method. + """ + return self.actual_instance + + @classmethod + def from_dict(cls, obj: dict) -> Self: + return cls.from_json(dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + instance = cls.model_construct() + error_messages = [] + + try: + instance.oneof_schema_1_validator = loads(json_str) + instance.actual_instance = instance.oneof_schema_1_validator + + return instance + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + try: + instance.oneof_schema_2_validator = loads(json_str) + instance.actual_instance = instance.oneof_schema_2_validator + + return instance + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + + raise ValueError( + "No match found when deserializing the JSON string into BuiltInOperationValue with oneOf schemas: int, str. Details: " + + ", ".join(error_messages) + ) + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is None: + return "null" + + to_json = getattr(self.actual_instance, "to_json", None) + if callable(to_json): + return self.actual_instance.to_json() + else: + return dumps(self.actual_instance) + + def to_dict(self) -> Dict: + """Returns the dict representation of the actual instance""" + if self.actual_instance is None: + return None + + to_dict = getattr(self.actual_instance, "to_dict", None) + if callable(to_dict): + return self.actual_instance.to_dict() + else: + return self.actual_instance diff --git a/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation.rb b/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation.rb index 9a41a582e7..101c4b756d 100644 --- a/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation.rb +++ b/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation.rb @@ -9,7 +9,6 @@ module Search class BuiltInOperation attr_accessor :_operation - # Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` value. attr_accessor :value class EnumAttributeValidator @@ -51,7 +50,7 @@ def self.acceptable_attributes def self.types_mapping { :_operation => :"BuiltInOperationType", - :value => :"String" + :value => :"BuiltInOperationValue" } end diff --git a/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation_value.rb b/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation_value.rb new file mode 100644 index 0000000000..90bd3904f0 --- /dev/null +++ b/clients/algoliasearch-client-ruby/lib/algolia/models/search/built_in_operation_value.rb @@ -0,0 +1,105 @@ +# 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. + +require "date" +require "time" + +module Algolia + module Search + module BuiltInOperationValue + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :"Integer", + :"String" + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + # "nullable: true" + next if klass == :AnyType + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + # rescue all errors so we keep iterating even if the current item lookup raises + rescue + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when "Boolean" + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when "Float" + return data if data.instance_of?(Float) + when "Integer" + return data if data.instance_of?(Integer) + when "Time" + return Time.parse(data) + when "Date" + return Date.parse(data) + when "String" + return data if data.instance_of?(String) + # "type: object" + when "Object" + return data if data.instance_of?(Hash) + # "type: array" + when /\AArray<(?.+)>\z/ + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + # "type: object" with "additionalProperties: { ... }" + when /\AHash.+)>\z/ + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + # model + else + const = Algolia::Search.const_get(klass) + if const + # nested oneOf model + if const.respond_to?(:openapi_one_of) + model = const.build(data) + else + # raise if data contains keys that are not known to the model + raise unless (data.keys - const.acceptable_attributes).empty? + model = const.build_from_hash(data) + end + + return model if model + end + end + + # if no match by now, raise + raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + + end +end diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperation.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperation.scala index a4b0f6ae1d..ad593120f1 100644 --- a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperation.scala +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperation.scala @@ -36,12 +36,8 @@ package algoliasearch.search import algoliasearch.search.BuiltInOperationType._ /** Update to perform on the attribute. - * - * @param value - * Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` - * value. */ case class BuiltInOperation( _operation: BuiltInOperationType, - value: String + value: BuiltInOperationValue ) extends AttributeToUpdateTrait diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperationValue.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperationValue.scala new file mode 100644 index 0000000000..012c46b2c7 --- /dev/null +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/BuiltInOperationValue.scala @@ -0,0 +1,73 @@ +/** Search API The Algolia Search API lets you search, configure, and mange your indices and records. ## Client + * libraries Use Algolia's API clients and libraries to reliably integrate Algolia's APIs with your apps. The official + * API clients are covered by Algolia's [Service Level Agreement](https://www.algolia.com/policies/sla/). See: + * [Algolia's ecosystem](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) ## + * Base URLs The base URLs for requests to the Search API are: - `https://{APPLICATION_ID}.algolia.net` - + * `https://{APPLICATION_ID}-dsn.algolia.net`. If your subscription includes a [Distributed Search + * Network](https://dashboard.algolia.com/infra), this ensures that requests are sent to servers closest to users. Both + * URLs provide high availability by distributing requests with load balancing. **All requests must use HTTPS.** ## + * Retry strategy To guarantee a high availability, implement a retry strategy for all API requests using the URLs of + * your servers as fallbacks: - `https://{APPLICATION_ID}-1.algolianet.com` - + * `https://{APPLICATION_ID}-2.algolianet.com` - `https://{APPLICATION_ID}-3.algolianet.com` These URLs use a different + * DNS provider than the primary URLs. You should randomize this list to ensure an even load across the three servers. + * All Algolia API clients implement this retry strategy. ## Authentication To authenticate your API requests, add + * these headers: - `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the + * necessary permissions to make the request. The required access control list (ACL) to make a request is listed in + * each endpoint's reference. You can find your application ID and API key in the [Algolia + * dashboard](https://dashboard.algolia.com/account). ## Request format Depending on the endpoint, request bodies are + * either JSON objects or arrays of JSON objects, ## Parameters Parameters are passed as query parameters for GET and + * DELETE requests, and in the request body for POST and PUT requests. Query parameters must be + * [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII characters must be + * UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. Arrays as query parameters must be one of: - A + * comma-separated string: `attributesToRetrieve=title,description` - A URL-encoded JSON array: + * `attributesToRetrieve=%5B%22title%22,%22description%22%D` ## Response status and errors The Search API returns JSON + * responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order of attributes in the API + * response. Successful responses return a `2xx` status. Client errors return a `4xx` status. Server errors are + * indicated by a `5xx` status. Error responses have a `message` property with more information. ## Version The current + * version of the Search API is version 1, as indicated by the `/1/` in each endpoint's URL. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech Do not edit the class manually. + */ +package algoliasearch.search + +import org.json4s._ + +/** BuiltInOperationValue + */ +sealed trait BuiltInOperationValue + +object BuiltInOperationValue { + + case class StringValue(value: String) extends BuiltInOperationValue + case class IntValue(value: Int) extends BuiltInOperationValue + + def apply(value: String): BuiltInOperationValue = { + BuiltInOperationValue.StringValue(value) + } + def apply(value: Int): BuiltInOperationValue = { + BuiltInOperationValue.IntValue(value) + } +} + +object BuiltInOperationValueSerializer extends Serializer[BuiltInOperationValue] { + override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), BuiltInOperationValue] = { + + case (TypeInfo(clazz, _), json) if clazz == classOf[BuiltInOperationValue] => + json match { + case JString(value) => BuiltInOperationValue.StringValue(value) + case JInt(value) => BuiltInOperationValue.IntValue(value.toInt) + case _ => throw new MappingException("Can't convert " + json + " to BuiltInOperationValue") + } + } + + override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { + case value: BuiltInOperationValue => + value match { + case BuiltInOperationValue.StringValue(value) => JString(value) + case BuiltInOperationValue.IntValue(value) => JInt(value) + } + } +} diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/JsonSupport.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/JsonSupport.scala index fb40567ce6..aad9354de3 100644 --- a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/JsonSupport.scala +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/search/JsonSupport.scala @@ -72,6 +72,7 @@ object JsonSupport { AttributeToUpdateSerializer :+ AutomaticFacetFiltersSerializer :+ BrowseParamsSerializer :+ + BuiltInOperationValueSerializer :+ ConsequenceQuerySerializer :+ DistinctSerializer :+ FacetFiltersSerializer :+ diff --git a/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperation.swift b/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperation.swift index 8d3f19af82..7556afb969 100644 --- a/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperation.swift +++ b/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperation.swift @@ -9,11 +9,9 @@ import Foundation /// Update to perform on the attribute. public struct BuiltInOperation: Codable, JSONEncodable { public var operation: BuiltInOperationType - /// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove` - /// value. - public var value: String + public var value: BuiltInOperationValue - public init(operation: BuiltInOperationType, value: String) { + public init(operation: BuiltInOperationType, value: BuiltInOperationValue) { self.operation = operation self.value = value } diff --git a/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperationValue.swift b/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperationValue.swift new file mode 100644 index 0000000000..07ad6ae812 --- /dev/null +++ b/clients/algoliasearch-client-swift/Sources/Search/Models/BuiltInOperationValue.swift @@ -0,0 +1,51 @@ +// 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. + +import Foundation +#if canImport(Core) + import Core +#endif + +public enum BuiltInOperationValue: Codable, JSONEncodable, AbstractEncodable { + case string(String) + case int(Int) + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + switch self { + case let .string(value): + try container.encode(value) + case let .int(value): + try container.encode(value) + } + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + if let value = try? container.decode(String.self) { + self = .string(value) + } else if let value = try? container.decode(Int.self) { + self = .int(value) + } else { + throw DecodingError.typeMismatch( + Self.Type.self, + .init( + codingPath: decoder.codingPath, + debugDescription: "Unable to decode instance of BuiltInOperationValue" + ) + ) + } + } + + public func GetActualInstance() -> Encodable { + switch self { + case let .string(value): + value as String + case let .int(value): + value as Int + } + } +} + +extension BuiltInOperationValue: Equatable {} +extension BuiltInOperationValue: Hashable {} diff --git a/snippets/csharp/src/Search.cs b/snippets/csharp/src/Search.cs index 13a98ec9bf..e0b89279df 100644 --- a/snippets/csharp/src/Search.cs +++ b/snippets/csharp/src/Search.cs @@ -1093,7 +1093,7 @@ public async Task SnippetForSearchClientOperationIndex2() /// /// Snippet for the PartialUpdateObject method. /// - /// partialUpdateObject + /// Partial update with string value /// public async Task SnippetForSearchClientPartialUpdateObject() { @@ -1114,7 +1114,7 @@ public async Task SnippetForSearchClientPartialUpdateObject() new BuiltInOperation { Operation = Enum.Parse("AddUnique"), - Value = "test2", + Value = new BuiltInOperationValue("test2"), } ) } diff --git a/snippets/dart/lib/search.dart b/snippets/dart/lib/search.dart index 9bfb419569..4bdcaa10f7 100644 --- a/snippets/dart/lib/search.dart +++ b/snippets/dart/lib/search.dart @@ -980,7 +980,7 @@ void snippetForoperationIndex2() async { // Snippet for the partialUpdateObject method. // -// partialUpdateObject +// Partial update with string value void snippetForpartialUpdateObject() async { // >SEPARATOR partialUpdateObject default // Initialize the client diff --git a/snippets/go/src/search.go b/snippets/go/src/search.go index 0ade98206b..3940af00f3 100644 --- a/snippets/go/src/search.go +++ b/snippets/go/src/search.go @@ -1516,7 +1516,7 @@ func SnippetForPartialUpdateObjectOfSearch() { /* Snippet for the partialUpdateObject method. - partialUpdateObject + Partial update with string value */ // >SEPARATOR partialUpdateObject default @@ -1530,7 +1530,7 @@ func SnippetForPartialUpdateObjectOfSearch() { // Call the API response, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest( "theIndexName", "uniqueID", map[string]search.AttributeToUpdate{"id1": *search.StringAsAttributeToUpdate("test"), "id2": *search.BuiltInOperationAsAttributeToUpdate( - search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue("test2"))}, + search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue(search.StringAsBuiltInOperationValue("test2")))}, ).WithCreateIfNotExists(true)) if err != nil { // handle the eventual error diff --git a/snippets/guides/search-snippets.json b/snippets/guides/search-snippets.json index 91fe325c11..c3e463ffe5 100644 --- a/snippets/guides/search-snippets.json +++ b/snippets/guides/search-snippets.json @@ -143,7 +143,7 @@ "move": "var response = await client.OperationIndexAsync(\n \"\",\n new OperationIndexParams\n {\n Operation = Enum.Parse(\"Move\"),\n Destination = \"\",\n }\n);" }, "partialUpdateObject": { - "default": "var response = await client.PartialUpdateObjectAsync(\n \"theIndexName\",\n \"uniqueID\",\n new Dictionary\n {\n { \"id1\", new AttributeToUpdate(\"test\") },\n {\n \"id2\",\n new AttributeToUpdate(\n new BuiltInOperation\n {\n Operation = Enum.Parse(\"AddUnique\"),\n Value = \"test2\",\n }\n )\n }\n },\n true\n);" + "default": "var response = await client.PartialUpdateObjectAsync(\n \"theIndexName\",\n \"uniqueID\",\n new Dictionary\n {\n { \"id1\", new AttributeToUpdate(\"test\") },\n {\n \"id2\",\n new AttributeToUpdate(\n new BuiltInOperation\n {\n Operation = Enum.Parse(\"AddUnique\"),\n Value = new BuiltInOperationValue(\"test2\"),\n }\n )\n }\n },\n true\n);" }, "removeUserId": { "default": "var response = await client.RemoveUserIdAsync(\"uniqueID\");" @@ -587,7 +587,7 @@ "move": "response, err := client.OperationIndex(client.NewApiOperationIndexRequest(\n \"\",\n search.NewEmptyOperationIndexParams().SetOperation(search.OperationType(\"move\")).SetDestination(\"\"),\n))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)" }, "partialUpdateObject": { - "default": "response, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest(\n \"theIndexName\", \"uniqueID\", map[string]search.AttributeToUpdate{\"id1\": *search.StringAsAttributeToUpdate(\"test\"), \"id2\": *search.BuiltInOperationAsAttributeToUpdate(\n search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType(\"AddUnique\")).SetValue(\"test2\"))},\n).WithCreateIfNotExists(true))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)" + "default": "response, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest(\n \"theIndexName\", \"uniqueID\", map[string]search.AttributeToUpdate{\"id1\": *search.StringAsAttributeToUpdate(\"test\"), \"id2\": *search.BuiltInOperationAsAttributeToUpdate(\n search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType(\"AddUnique\")).SetValue(search.StringAsBuiltInOperationValue(\"test2\")))},\n).WithCreateIfNotExists(true))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)" }, "removeUserId": { "default": "response, err := client.RemoveUserId(client.NewApiRemoveUserIdRequest(\n \"uniqueID\",\n))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)" @@ -809,7 +809,7 @@ "move": "client.operationIndex(\n \"\",\n new OperationIndexParams().setOperation(OperationType.MOVE).setDestination(\"\")\n);" }, "partialUpdateObject": { - "default": "client.partialUpdateObject(\n \"theIndexName\",\n \"uniqueID\",\n Map.of(\n \"id1\",\n AttributeToUpdate.of(\"test\"),\n \"id2\",\n new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue(\"test2\")\n ),\n true\n);" + "default": "client.partialUpdateObject(\n \"theIndexName\",\n \"uniqueID\",\n Map.of(\n \"id1\",\n AttributeToUpdate.of(\"test\"),\n \"id2\",\n new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue(BuiltInOperationValue.of(\"test2\"))\n ),\n true\n);" }, "removeUserId": { "default": "client.removeUserId(\"uniqueID\");" @@ -1253,7 +1253,7 @@ "move": "var response = client.operationIndex(\n indexName = \"\",\n operationIndexParams = OperationIndexParams(\n operation = OperationType.entries.first { it.value == \"move\" },\n destination = \"\",\n ),\n)\n\n// Use the response\nprintln(response)" }, "partialUpdateObject": { - "default": "var response = client.partialUpdateObject(\n indexName = \"theIndexName\",\n objectID = \"uniqueID\",\n attributesToUpdate = mapOf(\n \"id1\" to AttributeToUpdate.of(\"test\"),\n \"id2\" to BuiltInOperation(\n operation = BuiltInOperationType.entries.first { it.value == \"AddUnique\" },\n value = \"test2\",\n ),\n ),\n createIfNotExists = true,\n)\n\n// Use the response\nprintln(response)" + "default": "var response = client.partialUpdateObject(\n indexName = \"theIndexName\",\n objectID = \"uniqueID\",\n attributesToUpdate = mapOf(\n \"id1\" to AttributeToUpdate.of(\"test\"),\n \"id2\" to BuiltInOperation(\n operation = BuiltInOperationType.entries.first { it.value == \"AddUnique\" },\n value = BuiltInOperationValue.of(\"test2\"),\n ),\n ),\n createIfNotExists = true,\n)\n\n// Use the response\nprintln(response)" }, "removeUserId": { "default": "var response = client.removeUserId(\n userID = \"uniqueID\",\n)\n\n// Use the response\nprintln(response)" @@ -2141,7 +2141,7 @@ "move": "val response = client.operationIndex(\n indexName = \"\",\n operationIndexParams = OperationIndexParams(\n operation = OperationType.withName(\"move\"),\n destination = \"\"\n )\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" }, "partialUpdateObject": { - "default": "val response = client.partialUpdateObject(\n indexName = \"theIndexName\",\n objectID = \"uniqueID\",\n attributesToUpdate = Map(\n \"id1\" -> AttributeToUpdate(\"test\"),\n \"id2\" -> BuiltInOperation(\n _operation = BuiltInOperationType.withName(\"AddUnique\"),\n value = \"test2\"\n )\n ),\n createIfNotExists = Some(true)\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" + "default": "val response = client.partialUpdateObject(\n indexName = \"theIndexName\",\n objectID = \"uniqueID\",\n attributesToUpdate = Map(\n \"id1\" -> AttributeToUpdate(\"test\"),\n \"id2\" -> BuiltInOperation(\n _operation = BuiltInOperationType.withName(\"AddUnique\"),\n value = BuiltInOperationValue(\"test2\")\n )\n ),\n createIfNotExists = Some(true)\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" }, "removeUserId": { "default": "val response = client.removeUserId(\n userID = \"uniqueID\"\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" @@ -2363,7 +2363,7 @@ "move": "let response = try await client.operationIndex(\n indexName: \"\",\n operationIndexParams: OperationIndexParams(\n operation: OperationType.move,\n destination: \"\"\n )\n)" }, "partialUpdateObject": { - "default": "let response = try await client.partialUpdateObject(\n indexName: \"theIndexName\",\n objectID: \"uniqueID\",\n attributesToUpdate: [\n \"id1\": AttributeToUpdate.string(\"test\"),\n \"id2\": AttributeToUpdate\n .builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: \"test2\")),\n ],\n createIfNotExists: true\n)" + "default": "let response = try await client.partialUpdateObject(\n indexName: \"theIndexName\",\n objectID: \"uniqueID\",\n attributesToUpdate: [\n \"id1\": AttributeToUpdate.string(\"test\"),\n \"id2\": AttributeToUpdate\n .builtInOperation(BuiltInOperation(\n operation: BuiltInOperationType.addUnique,\n value: BuiltInOperationValue.string(\"test2\")\n )),\n ],\n createIfNotExists: true\n)" }, "removeUserId": { "default": "let response = try await client.removeUserId(userID: \"uniqueID\")" diff --git a/snippets/java/src/test/java/com/algolia/Search.java b/snippets/java/src/test/java/com/algolia/Search.java index da8d7d2807..bccb37e818 100644 --- a/snippets/java/src/test/java/com/algolia/Search.java +++ b/snippets/java/src/test/java/com/algolia/Search.java @@ -800,7 +800,7 @@ void snippetForOperationIndex2() { // Snippet for the partialUpdateObject method. // - // partialUpdateObject + // Partial update with string value void snippetForPartialUpdateObject() { // >SEPARATOR partialUpdateObject default // Initialize the client @@ -814,7 +814,7 @@ void snippetForPartialUpdateObject() { "id1", AttributeToUpdate.of("test"), "id2", - new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue("test2") + new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue(BuiltInOperationValue.of("test2")) ), true ); diff --git a/snippets/javascript/src/search.ts b/snippets/javascript/src/search.ts index b8f430ac85..4c49d7b370 100644 --- a/snippets/javascript/src/search.ts +++ b/snippets/javascript/src/search.ts @@ -1011,7 +1011,7 @@ export async function snippetForOperationIndex2(): Promise { // Snippet for the partialUpdateObject method. // -// partialUpdateObject +// Partial update with string value export async function snippetForPartialUpdateObject(): Promise { // >SEPARATOR partialUpdateObject default // Initialize the client diff --git a/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Search.kt b/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Search.kt index 414c1a5cf7..ce13e68b21 100644 --- a/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Search.kt +++ b/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Search.kt @@ -1121,7 +1121,7 @@ class SnippetSearchClient { "id1" to AttributeToUpdate.of("test"), "id2" to BuiltInOperation( operation = BuiltInOperationType.entries.first { it.value == "AddUnique" }, - value = "test2", + value = BuiltInOperationValue.of("test2"), ), ), createIfNotExists = true, diff --git a/snippets/php/src/Search.php b/snippets/php/src/Search.php index 63cac3bdd6..7e1ea19dec 100644 --- a/snippets/php/src/Search.php +++ b/snippets/php/src/Search.php @@ -1269,7 +1269,7 @@ public function snippetForOperationIndex2() /** * Snippet for the PartialUpdateObject method. * - * partialUpdateObject + * Partial update with string value */ public function snippetForPartialUpdateObject() { diff --git a/snippets/python/search.py b/snippets/python/search.py index d7c2a3cf6f..30777ccadb 100644 --- a/snippets/python/search.py +++ b/snippets/python/search.py @@ -1407,7 +1407,7 @@ async def snippet_for_partial_update_object(): """ Snippet for the partialUpdateObject method. - partialUpdateObject + Partial update with string value """ # >SEPARATOR partialUpdateObject default # Initialize the client diff --git a/snippets/ruby/search.rb b/snippets/ruby/search.rb index 6facadfd1e..3d8c1c5054 100644 --- a/snippets/ruby/search.rb +++ b/snippets/ruby/search.rb @@ -1107,7 +1107,7 @@ def snippet_for_operation_index2 # Snippet for the partialUpdateObject method. # -# partialUpdateObject +# Partial update with string value def snippet_for_partial_update_object # >SEPARATOR partialUpdateObject default # Initialize the client diff --git a/snippets/scala/src/main/scala/Search.scala b/snippets/scala/src/main/scala/Search.scala index b6ed45750b..2e37a7d37f 100644 --- a/snippets/scala/src/main/scala/Search.scala +++ b/snippets/scala/src/main/scala/Search.scala @@ -1172,7 +1172,7 @@ class SnippetSearchClient { /** Snippet for the partialUpdateObject method. * - * partialUpdateObject + * Partial update with string value */ def snippetForSearchClientPartialUpdateObject(): Unit = { // >SEPARATOR partialUpdateObject default @@ -1187,7 +1187,7 @@ class SnippetSearchClient { "id1" -> AttributeToUpdate("test"), "id2" -> BuiltInOperation( _operation = BuiltInOperationType.withName("AddUnique"), - value = "test2" + value = BuiltInOperationValue("test2") ) ), createIfNotExists = Some(true) diff --git a/snippets/swift/Sources/Search.swift b/snippets/swift/Sources/Search.swift index 438bb227d6..489bbc21ac 100644 --- a/snippets/swift/Sources/Search.swift +++ b/snippets/swift/Sources/Search.swift @@ -829,7 +829,7 @@ final class SearchClientSnippet { /// Snippet for the partialUpdateObject method. /// - /// partialUpdateObject + /// Partial update with string value func snippetForPartialUpdateObject() async throws { // >SEPARATOR partialUpdateObject default // Initialize the client @@ -842,7 +842,10 @@ final class SearchClientSnippet { attributesToUpdate: [ "id1": AttributeToUpdate.string("test"), "id2": AttributeToUpdate - .builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: "test2")), + .builtInOperation(BuiltInOperation( + operation: BuiltInOperationType.addUnique, + value: BuiltInOperationValue.string("test2") + )), ], createIfNotExists: true ) diff --git a/specs/bundled/search.doc.yml b/specs/bundled/search.doc.yml index e94ab9f625..08c40ae4c6 100644 --- a/specs/bundled/search.doc.yml +++ b/specs/bundled/search.doc.yml @@ -3778,7 +3778,7 @@ paths: new BuiltInOperation { Operation = Enum.Parse("AddUnique"), - Value = "test2", + Value = new BuiltInOperationValue("test2"), } ) } @@ -3826,7 +3826,7 @@ paths: response, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest( "theIndexName", "uniqueID", map[string]search.AttributeToUpdate{"id1": *search.StringAsAttributeToUpdate("test"), "id2": *search.BuiltInOperationAsAttributeToUpdate( - search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue("test2"))}, + search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue(search.StringAsBuiltInOperationValue("test2")))}, ).WithCreateIfNotExists(true)) if err != nil { @@ -3856,7 +3856,7 @@ paths: "id1", AttributeToUpdate.of("test"), "id2", - new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue("test2") + new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue(BuiltInOperationValue.of("test2")) ), true ); @@ -3897,7 +3897,7 @@ paths: "id1" to AttributeToUpdate.of("test"), "id2" to BuiltInOperation( operation = BuiltInOperationType.entries.first { it.value == "AddUnique" }, - value = "test2", + value = BuiltInOperationValue.of("test2"), ), ), createIfNotExists = true, @@ -3989,7 +3989,7 @@ paths: "id1" -> AttributeToUpdate("test"), "id2" -> BuiltInOperation( _operation = BuiltInOperationType.withName("AddUnique"), - value = "test2" + value = BuiltInOperationValue("test2") ) ), createIfNotExists = Some(true) @@ -4016,7 +4016,10 @@ paths: attributesToUpdate: [ "id1": AttributeToUpdate.string("test"), "id2": AttributeToUpdate - .builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: "test2")), + .builtInOperation(BuiltInOperation( + operation: BuiltInOperationType.addUnique, + value: BuiltInOperationValue.string("test2") + )), ], createIfNotExists: true ) @@ -18186,6 +18189,14 @@ components: - IncrementFrom - IncrementSet description: How to change the attribute. + builtInOperationValue: + oneOf: + - type: string + description: >- + A string to append or remove for the `Add`, `Remove`, and + `AddUnique` operations. + - type: integer + description: A number to add, remove, or append, depending on the operation. builtInOperation: type: object description: Update to perform on the attribute. @@ -18194,10 +18205,7 @@ components: _operation: $ref: '#/components/schemas/builtInOperationType' value: - type: string - description: >- - Value that corresponds to the operation, for example an `Increment` - or `Decrement` step, or an `Add` or `Remove` value. + $ref: '#/components/schemas/builtInOperationValue' required: - _operation - value diff --git a/specs/bundled/search.yml b/specs/bundled/search.yml index 903b7bdccd..f1e9be8203 100644 --- a/specs/bundled/search.yml +++ b/specs/bundled/search.yml @@ -6142,6 +6142,14 @@ components: - IncrementFrom - IncrementSet description: How to change the attribute. + builtInOperationValue: + oneOf: + - type: string + description: >- + A string to append or remove for the `Add`, `Remove`, and + `AddUnique` operations. + - type: integer + description: A number to add, remove, or append, depending on the operation. builtInOperation: type: object description: Update to perform on the attribute. @@ -6150,10 +6158,7 @@ components: _operation: $ref: '#/components/schemas/builtInOperationType' value: - type: string - description: >- - Value that corresponds to the operation, for example an `Increment` - or `Decrement` step, or an `Add` or `Remove` value. + $ref: '#/components/schemas/builtInOperationValue' required: - _operation - value diff --git a/tests/output/csharp/src/generated/e2e/Insights.test.cs b/tests/output/csharp/src/generated/e2e/Insights.test.cs index 1da2d2f6b4..3c9764a57f 100644 --- a/tests/output/csharp/src/generated/e2e/Insights.test.cs +++ b/tests/output/csharp/src/generated/e2e/Insights.test.cs @@ -63,7 +63,7 @@ public async Task PushEventsTest1() Index = "products", UserToken = "user-123456", AuthenticatedUserToken = "user-123456", - Timestamp = 1722124800000L, + Timestamp = 1722384000000L, ObjectIDs = new List { "9780545139700", "9780439784542" }, QueryID = "43b15df305339e827f0ac0bdc5ebcaa7", } @@ -76,7 +76,7 @@ public async Task PushEventsTest1() Index = "products", UserToken = "user-123456", AuthenticatedUserToken = "user-123456", - Timestamp = 1722124800000L, + Timestamp = 1722384000000L, ObjectIDs = new List { "9780545139700", "9780439784542" }, } ) diff --git a/tests/output/csharp/src/generated/requests/Insights.test.cs b/tests/output/csharp/src/generated/requests/Insights.test.cs index f77ff777b7..1622624bef 100644 --- a/tests/output/csharp/src/generated/requests/Insights.test.cs +++ b/tests/output/csharp/src/generated/requests/Insights.test.cs @@ -580,7 +580,7 @@ await client.PushEventsAsync( Index = "products", UserToken = "user-123456", AuthenticatedUserToken = "user-123456", - Timestamp = 1722124800000L, + Timestamp = 1722384000000L, ObjectIDs = new List { "9780545139700", "9780439784542" }, QueryID = "43b15df305339e827f0ac0bdc5ebcaa7", } @@ -593,7 +593,7 @@ await client.PushEventsAsync( Index = "products", UserToken = "user-123456", AuthenticatedUserToken = "user-123456", - Timestamp = 1722124800000L, + Timestamp = 1722384000000L, ObjectIDs = new List { "9780545139700", "9780439784542" }, } ) @@ -605,7 +605,7 @@ await client.PushEventsAsync( Assert.Equal("/1/events", req.Path); Assert.Equal("POST", req.Method.ToString()); JsonAssert.EqualOverrideDefault( - "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}", + "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}", req.Body, new JsonDiffConfig(false) ); diff --git a/tests/output/csharp/src/generated/requests/Search.test.cs b/tests/output/csharp/src/generated/requests/Search.test.cs index 5a3ebd3e18..9c50082416 100644 --- a/tests/output/csharp/src/generated/requests/Search.test.cs +++ b/tests/output/csharp/src/generated/requests/Search.test.cs @@ -1568,7 +1568,7 @@ await client.OperationIndexAsync( ); } - [Fact(DisplayName = "partialUpdateObject")] + [Fact(DisplayName = "Partial update with string value")] public async Task PartialUpdateObjectTest() { await client.PartialUpdateObjectAsync( @@ -1583,7 +1583,7 @@ await client.PartialUpdateObjectAsync( new BuiltInOperation { Operation = Enum.Parse("AddUnique"), - Value = "test2", + Value = new BuiltInOperationValue("test2"), } ) } @@ -1614,6 +1614,37 @@ await client.PartialUpdateObjectAsync( } } + [Fact(DisplayName = "Partial update with integer value")] + public async Task PartialUpdateObjectTest1() + { + await client.PartialUpdateObjectAsync( + "theIndexName", + "uniqueID", + new Dictionary + { + { + "attributeId", + new AttributeToUpdate( + new BuiltInOperation + { + Operation = Enum.Parse("Increment"), + Value = new BuiltInOperationValue(2), + } + ) + } + } + ); + + var req = _echo.LastResponse; + Assert.Equal("/1/indexes/theIndexName/uniqueID/partial", req.Path); + Assert.Equal("POST", req.Method.ToString()); + JsonAssert.EqualOverrideDefault( + "{\"attributeId\":{\"_operation\":\"Increment\",\"value\":2}}", + req.Body, + new JsonDiffConfig(false) + ); + } + [Fact(DisplayName = "removeUserId")] public async Task RemoveUserIdTest() { diff --git a/tests/output/dart/test/requests/insights_test.dart b/tests/output/dart/test/requests/insights_test.dart index 96ed7f5ddf..66d946b27b 100644 --- a/tests/output/dart/test/requests/insights_test.dart +++ b/tests/output/dart/test/requests/insights_test.dart @@ -633,7 +633,7 @@ void main() { index: "products", userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: [ "9780545139700", "9780439784542", @@ -646,7 +646,7 @@ void main() { index: "products", userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: [ "9780545139700", "9780439784542", @@ -659,7 +659,7 @@ void main() { expectPath(request.path, '/1/events'); expect(request.method, 'post'); expectBody(request.body, - """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}"""); + """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}"""); }, ), ); diff --git a/tests/output/dart/test/requests/search_test.dart b/tests/output/dart/test/requests/search_test.dart index 18ff02d9af..6d72ec89bb 100644 --- a/tests/output/dart/test/requests/search_test.dart +++ b/tests/output/dart/test/requests/search_test.dart @@ -1909,7 +1909,7 @@ void main() { // partialUpdateObject test( - 'partialUpdateObject', + 'Partial update with string value', () => runTest( builder: (requester) => SearchClient( appId: 'appId', @@ -1939,6 +1939,34 @@ void main() { ), ); + // partialUpdateObject + test( + 'Partial update with integer value', + () => runTest( + builder: (requester) => SearchClient( + appId: 'appId', + apiKey: 'apiKey', + options: ClientOptions(requester: requester), + ), + call: (client) => client.partialUpdateObject( + indexName: "theIndexName", + objectID: "uniqueID", + attributesToUpdate: { + 'attributeId': BuiltInOperation( + operation: BuiltInOperationType.fromJson("Increment"), + value: 2, + ), + }, + ), + intercept: (request) { + expectPath(request.path, '/1/indexes/theIndexName/uniqueID/partial'); + expect(request.method, 'post'); + expectBody(request.body, + """{"attributeId":{"_operation":"Increment","value":2}}"""); + }, + ), + ); + // removeUserId test( 'removeUserId', diff --git a/tests/output/go/tests/e2e/insights_test.go b/tests/output/go/tests/e2e/insights_test.go index c20f00eac1..1ad7a44615 100644 --- a/tests/output/go/tests/e2e/insights_test.go +++ b/tests/output/go/tests/e2e/insights_test.go @@ -38,9 +38,9 @@ func TestInsightsE2E_PushEvents(t *testing.T) { insights.NewEmptyInsightsEvents().SetEvents( []insights.EventsItems{*insights.ConvertedObjectIDsAfterSearchAsEventsItems( - insights.NewEmptyConvertedObjectIDsAfterSearch().SetEventType(insights.ConversionEvent("conversion")).SetEventName("Product Purchased").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722124800000).SetObjectIDs( + insights.NewEmptyConvertedObjectIDsAfterSearch().SetEventType(insights.ConversionEvent("conversion")).SetEventName("Product Purchased").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722384000000).SetObjectIDs( []string{"9780545139700", "9780439784542"}).SetQueryID("43b15df305339e827f0ac0bdc5ebcaa7")), *insights.ViewedObjectIDsAsEventsItems( - insights.NewEmptyViewedObjectIDs().SetEventType(insights.ViewEvent("view")).SetEventName("Product Detail Page Viewed").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722124800000).SetObjectIDs( + insights.NewEmptyViewedObjectIDs().SetEventType(insights.ViewEvent("view")).SetEventName("Product Detail Page Viewed").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722384000000).SetObjectIDs( []string{"9780545139700", "9780439784542"}))}), )) require.NoError(t, err) diff --git a/tests/output/go/tests/requests/insights_test.go b/tests/output/go/tests/requests/insights_test.go index 084bb9d684..1c7dbbae38 100644 --- a/tests/output/go/tests/requests/insights_test.go +++ b/tests/output/go/tests/requests/insights_test.go @@ -433,9 +433,9 @@ func TestInsights_PushEvents(t *testing.T) { insights.NewEmptyInsightsEvents().SetEvents( []insights.EventsItems{*insights.ConvertedObjectIDsAfterSearchAsEventsItems( - insights.NewEmptyConvertedObjectIDsAfterSearch().SetEventType(insights.ConversionEvent("conversion")).SetEventName("Product Purchased").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722124800000).SetObjectIDs( + insights.NewEmptyConvertedObjectIDsAfterSearch().SetEventType(insights.ConversionEvent("conversion")).SetEventName("Product Purchased").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722384000000).SetObjectIDs( []string{"9780545139700", "9780439784542"}).SetQueryID("43b15df305339e827f0ac0bdc5ebcaa7")), *insights.ViewedObjectIDsAsEventsItems( - insights.NewEmptyViewedObjectIDs().SetEventType(insights.ViewEvent("view")).SetEventName("Product Detail Page Viewed").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722124800000).SetObjectIDs( + insights.NewEmptyViewedObjectIDs().SetEventType(insights.ViewEvent("view")).SetEventName("Product Detail Page Viewed").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1722384000000).SetObjectIDs( []string{"9780545139700", "9780439784542"}))}), )) require.NoError(t, err) @@ -444,7 +444,7 @@ func TestInsights_PushEvents(t *testing.T) { require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.Body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}`) }) t.Run("ConvertedObjectIDsAfterSearch", func(t *testing.T) { _, err := client.PushEvents(client.NewApiPushEventsRequest( diff --git a/tests/output/go/tests/requests/search_test.go b/tests/output/go/tests/requests/search_test.go index 30df084828..60e74e36c7 100644 --- a/tests/output/go/tests/requests/search_test.go +++ b/tests/output/go/tests/requests/search_test.go @@ -1343,10 +1343,10 @@ func TestSearch_PartialUpdateObject(t *testing.T) { client, echo := createSearchClient(t) _ = echo - t.Run("partialUpdateObject", func(t *testing.T) { + t.Run("Partial update with string value", func(t *testing.T) { _, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest( "theIndexName", "uniqueID", map[string]search.AttributeToUpdate{"id1": *search.StringAsAttributeToUpdate("test"), "id2": *search.BuiltInOperationAsAttributeToUpdate( - search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue("test2"))}, + search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("AddUnique")).SetValue(search.StringAsBuiltInOperationValue("test2")))}, ).WithCreateIfNotExists(true)) require.NoError(t, err) @@ -1362,6 +1362,19 @@ func TestSearch_PartialUpdateObject(t *testing.T) { require.Equal(t, v, echo.Query.Get(k)) } }) + t.Run("Partial update with integer value", func(t *testing.T) { + _, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest( + "theIndexName", "uniqueID", map[string]search.AttributeToUpdate{"attributeId": *search.BuiltInOperationAsAttributeToUpdate( + search.NewEmptyBuiltInOperation().SetOperation(search.BuiltInOperationType("Increment")).SetValue(search.Int32AsBuiltInOperationValue(2)))}, + )) + require.NoError(t, err) + + require.Equal(t, "/1/indexes/theIndexName/uniqueID/partial", echo.Path) + require.Equal(t, "POST", echo.Method) + + ja := jsonassert.New(t) + ja.Assertf(*echo.Body, `{"attributeId":{"_operation":"Increment","value":2}}`) + }) } func TestSearch_RemoveUserId(t *testing.T) { diff --git a/tests/output/java/src/test/java/com/algolia/e2e/Insights.test.java b/tests/output/java/src/test/java/com/algolia/e2e/Insights.test.java index da8e5f9c1d..82008ef406 100644 --- a/tests/output/java/src/test/java/com/algolia/e2e/Insights.test.java +++ b/tests/output/java/src/test/java/com/algolia/e2e/Insights.test.java @@ -50,7 +50,7 @@ void pushEventsTest1() { .setIndex("products") .setUserToken("user-123456") .setAuthenticatedUserToken("user-123456") - .setTimestamp(1722124800000L) + .setTimestamp(1722384000000L) .setObjectIDs(List.of("9780545139700", "9780439784542")) .setQueryID("43b15df305339e827f0ac0bdc5ebcaa7"), new ViewedObjectIDs() @@ -59,7 +59,7 @@ void pushEventsTest1() { .setIndex("products") .setUserToken("user-123456") .setAuthenticatedUserToken("user-123456") - .setTimestamp(1722124800000L) + .setTimestamp(1722384000000L) .setObjectIDs(List.of("9780545139700", "9780439784542")) ) ) diff --git a/tests/output/java/src/test/java/com/algolia/requests/Insights.test.java b/tests/output/java/src/test/java/com/algolia/requests/Insights.test.java index 999bc29b05..aa1443365c 100644 --- a/tests/output/java/src/test/java/com/algolia/requests/Insights.test.java +++ b/tests/output/java/src/test/java/com/algolia/requests/Insights.test.java @@ -606,7 +606,7 @@ void pushEventsTest1() { .setIndex("products") .setUserToken("user-123456") .setAuthenticatedUserToken("user-123456") - .setTimestamp(1722124800000L) + .setTimestamp(1722384000000L) .setObjectIDs(List.of("9780545139700", "9780439784542")) .setQueryID("43b15df305339e827f0ac0bdc5ebcaa7"), new ViewedObjectIDs() @@ -615,7 +615,7 @@ void pushEventsTest1() { .setIndex("products") .setUserToken("user-123456") .setAuthenticatedUserToken("user-123456") - .setTimestamp(1722124800000L) + .setTimestamp(1722384000000L) .setObjectIDs(List.of("9780545139700", "9780439784542")) ) ) @@ -627,9 +627,9 @@ void pushEventsTest1() { assertDoesNotThrow(() -> JSONAssert.assertEquals( "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product" + - " Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product" + + " Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product" + " Detail Page" + - " Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}", + " Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}", req.body, JSONCompareMode.STRICT ) diff --git a/tests/output/java/src/test/java/com/algolia/requests/Search.test.java b/tests/output/java/src/test/java/com/algolia/requests/Search.test.java index addbd3dbab..c9989e24ba 100644 --- a/tests/output/java/src/test/java/com/algolia/requests/Search.test.java +++ b/tests/output/java/src/test/java/com/algolia/requests/Search.test.java @@ -1539,7 +1539,7 @@ void operationIndexTest2() { } @Test - @DisplayName("partialUpdateObject") + @DisplayName("Partial update with string value") void partialUpdateObjectTest() { assertDoesNotThrow(() -> { client.partialUpdateObject( @@ -1549,7 +1549,7 @@ void partialUpdateObjectTest() { "id1", AttributeToUpdate.of("test"), "id2", - new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue("test2") + new BuiltInOperation().setOperation(BuiltInOperationType.ADD_UNIQUE).setValue(BuiltInOperationValue.of("test2")) ), true ); @@ -1581,6 +1581,24 @@ void partialUpdateObjectTest() { } } + @Test + @DisplayName("Partial update with integer value") + void partialUpdateObjectTest1() { + assertDoesNotThrow(() -> { + client.partialUpdateObject( + "theIndexName", + "uniqueID", + Map.of("attributeId", new BuiltInOperation().setOperation(BuiltInOperationType.INCREMENT).setValue(BuiltInOperationValue.of(2))) + ); + }); + EchoResponse req = echo.getLastResponse(); + assertEquals("/1/indexes/theIndexName/uniqueID/partial", req.path); + assertEquals("POST", req.method); + assertDoesNotThrow(() -> + JSONAssert.assertEquals("{\"attributeId\":{\"_operation\":\"Increment\",\"value\":2}}", req.body, JSONCompareMode.STRICT) + ); + } + @Test @DisplayName("removeUserId") void removeUserIdTest() { diff --git a/tests/output/javascript/src/e2e/insights.test.ts b/tests/output/javascript/src/e2e/insights.test.ts index aafba8606d..fa8bb21cc3 100644 --- a/tests/output/javascript/src/e2e/insights.test.ts +++ b/tests/output/javascript/src/e2e/insights.test.ts @@ -34,7 +34,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -44,7 +44,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], }, ], diff --git a/tests/output/javascript/src/requests/insights.test.ts b/tests/output/javascript/src/requests/insights.test.ts index 6c8a58d9d7..fdc761682f 100644 --- a/tests/output/javascript/src/requests/insights.test.ts +++ b/tests/output/javascript/src/requests/insights.test.ts @@ -384,7 +384,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -394,7 +394,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], }, ], @@ -410,7 +410,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -420,7 +420,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1722124800000, + timestamp: 1722384000000, objectIDs: ['9780545139700', '9780439784542'], }, ], diff --git a/tests/output/javascript/src/requests/search.test.ts b/tests/output/javascript/src/requests/search.test.ts index 57ea350e74..242ddc23d9 100644 --- a/tests/output/javascript/src/requests/search.test.ts +++ b/tests/output/javascript/src/requests/search.test.ts @@ -1220,7 +1220,7 @@ describe('operationIndex', () => { }); describe('partialUpdateObject', () => { - test('partialUpdateObject', async () => { + test('Partial update with string value', async () => { const req = (await client.partialUpdateObject({ indexName: 'theIndexName', objectID: 'uniqueID', @@ -1239,6 +1239,23 @@ describe('partialUpdateObject', () => { }); expect(req.searchParams).toStrictEqual({ createIfNotExists: 'true' }); }); + + test('Partial update with integer value', async () => { + const req = (await client.partialUpdateObject({ + indexName: 'theIndexName', + objectID: 'uniqueID', + attributesToUpdate: { + attributeId: { _operation: 'Increment', value: 2 }, + }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/indexes/theIndexName/uniqueID/partial'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ + attributeId: { _operation: 'Increment', value: 2 }, + }); + expect(req.searchParams).toStrictEqual(undefined); + }); }); describe('removeUserId', () => { diff --git a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/InsightsTest.kt b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/InsightsTest.kt index 59866de053..4b83b35cfe 100644 --- a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/InsightsTest.kt +++ b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/InsightsTest.kt @@ -529,7 +529,7 @@ class InsightsTest { index = "products", userToken = "user-123456", authenticatedUserToken = "user-123456", - timestamp = 1722124800000L, + timestamp = 1722384000000L, objectIDs = listOf("9780545139700", "9780439784542"), queryID = "43b15df305339e827f0ac0bdc5ebcaa7", ), @@ -539,7 +539,7 @@ class InsightsTest { index = "products", userToken = "user-123456", authenticatedUserToken = "user-123456", - timestamp = 1722124800000L, + timestamp = 1722384000000L, objectIDs = listOf("9780545139700", "9780439784542"), ), ), @@ -549,7 +549,7 @@ class InsightsTest { intercept = { assertEquals("/1/events".toPathSegments(), it.url.pathSegments) assertEquals(HttpMethod.parse("POST"), it.method) - assertJsonBody("""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}""", it.body) + assertJsonBody("""{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}""", it.body) }, ) } diff --git a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/SearchTest.kt b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/SearchTest.kt index 062b5fd7a2..e3457d5a02 100644 --- a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/SearchTest.kt +++ b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/SearchTest.kt @@ -1679,7 +1679,7 @@ class SearchTest { // partialUpdateObject @Test - fun `partialUpdateObject`() = runTest { + fun `Partial update with string value`() = runTest { client.runTest( call = { partialUpdateObject( @@ -1689,7 +1689,7 @@ class SearchTest { "id1" to AttributeToUpdate.of("test"), "id2" to BuiltInOperation( operation = BuiltInOperationType.entries.first { it.value == "AddUnique" }, - value = "test2", + value = BuiltInOperationValue.of("test2"), ), ), createIfNotExists = true, @@ -1704,6 +1704,29 @@ class SearchTest { ) } + @Test + fun `Partial update with integer value1`() = runTest { + client.runTest( + call = { + partialUpdateObject( + indexName = "theIndexName", + objectID = "uniqueID", + attributesToUpdate = mapOf( + "attributeId" to BuiltInOperation( + operation = BuiltInOperationType.entries.first { it.value == "Increment" }, + value = BuiltInOperationValue.of(2), + ), + ), + ) + }, + intercept = { + assertEquals("/1/indexes/theIndexName/uniqueID/partial".toPathSegments(), it.url.pathSegments) + assertEquals(HttpMethod.parse("POST"), it.method) + assertJsonBody("""{"attributeId":{"_operation":"Increment","value":2}}""", it.body) + }, + ) + } + // removeUserId @Test diff --git a/tests/output/php/src/e2e/InsightsTest.php b/tests/output/php/src/e2e/InsightsTest.php index 63271326ec..fcb13889f0 100644 --- a/tests/output/php/src/e2e/InsightsTest.php +++ b/tests/output/php/src/e2e/InsightsTest.php @@ -35,7 +35,7 @@ public function testPushEvents1() 'index' => 'products', 'userToken' => 'user-123456', 'authenticatedUserToken' => 'user-123456', - 'timestamp' => 1722124800000, + 'timestamp' => 1722384000000, 'objectIDs' => [ '9780545139700', @@ -49,7 +49,7 @@ public function testPushEvents1() 'index' => 'products', 'userToken' => 'user-123456', 'authenticatedUserToken' => 'user-123456', - 'timestamp' => 1722124800000, + 'timestamp' => 1722384000000, 'objectIDs' => [ '9780545139700', diff --git a/tests/output/php/src/requests/InsightsTest.php b/tests/output/php/src/requests/InsightsTest.php index e2eac3c86b..531e14b613 100644 --- a/tests/output/php/src/requests/InsightsTest.php +++ b/tests/output/php/src/requests/InsightsTest.php @@ -527,7 +527,7 @@ public function testPushEvents1() 'index' => 'products', 'userToken' => 'user-123456', 'authenticatedUserToken' => 'user-123456', - 'timestamp' => 1722124800000, + 'timestamp' => 1722384000000, 'objectIDs' => [ '9780545139700', @@ -541,7 +541,7 @@ public function testPushEvents1() 'index' => 'products', 'userToken' => 'user-123456', 'authenticatedUserToken' => 'user-123456', - 'timestamp' => 1722124800000, + 'timestamp' => 1722384000000, 'objectIDs' => [ '9780545139700', @@ -556,7 +556,7 @@ public function testPushEvents1() [ 'path' => '/1/events', 'method' => 'POST', - 'body' => json_decode('{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}'), + 'body' => json_decode('{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}'), ], ]); } diff --git a/tests/output/php/src/requests/SearchTest.php b/tests/output/php/src/requests/SearchTest.php index 81f992fb0d..fdabbff4c8 100644 --- a/tests/output/php/src/requests/SearchTest.php +++ b/tests/output/php/src/requests/SearchTest.php @@ -1596,7 +1596,7 @@ public function testOperationIndex2() ]); } - #[TestDox('partialUpdateObject')] + #[TestDox('Partial update with string value')] public function testPartialUpdateObject() { $client = $this->getClient(); @@ -1621,6 +1621,28 @@ public function testPartialUpdateObject() ]); } + #[TestDox('Partial update with integer value')] + public function testPartialUpdateObject1() + { + $client = $this->getClient(); + $client->partialUpdateObject( + 'theIndexName', + 'uniqueID', + ['attributeId' => ['_operation' => 'Increment', + 'value' => 2, + ], + ], + ); + + $this->assertRequests([ + [ + 'path' => '/1/indexes/theIndexName/uniqueID/partial', + 'method' => 'POST', + 'body' => json_decode('{"attributeId":{"_operation":"Increment","value":2}}'), + ], + ]); + } + #[TestDox('removeUserId')] public function testRemoveUserId() { diff --git a/tests/output/python/tests/e2e/insights_test.py b/tests/output/python/tests/e2e/insights_test.py index 5541afd418..f2c80e5b75 100644 --- a/tests/output/python/tests/e2e/insights_test.py +++ b/tests/output/python/tests/e2e/insights_test.py @@ -35,7 +35,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", @@ -48,7 +48,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", @@ -70,7 +70,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", @@ -83,7 +83,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", diff --git a/tests/output/python/tests/requests/insights_test.py b/tests/output/python/tests/requests/insights_test.py index ff65c5ee89..56b51b999d 100644 --- a/tests/output/python/tests/requests/insights_test.py +++ b/tests/output/python/tests/requests/insights_test.py @@ -461,7 +461,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", @@ -474,7 +474,7 @@ async def test_push_events_1(self): "index": "products", "userToken": "user-123456", "authenticatedUserToken": "user-123456", - "timestamp": 1722124800000, + "timestamp": 1722384000000, "objectIDs": [ "9780545139700", "9780439784542", @@ -489,7 +489,7 @@ async def test_push_events_1(self): assert _req.query_parameters.items() == {}.items() assert _req.headers.items() >= {}.items() assert loads(_req.data) == loads( - """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}""" + """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}""" ) async def test_push_events_2(self): diff --git a/tests/output/python/tests/requests/search_test.py b/tests/output/python/tests/requests/search_test.py index b83ce385e4..b9633982b2 100644 --- a/tests/output/python/tests/requests/search_test.py +++ b/tests/output/python/tests/requests/search_test.py @@ -1452,7 +1452,7 @@ async def test_operation_index_2(self): async def test_partial_update_object_(self): """ - partialUpdateObject + Partial update with string value """ _req = await self._client.partial_update_object_with_http_info( index_name="theIndexName", @@ -1475,6 +1475,29 @@ async def test_partial_update_object_(self): """{"id1":"test","id2":{"_operation":"AddUnique","value":"test2"}}""" ) + async def test_partial_update_object_1(self): + """ + Partial update with integer value + """ + _req = await self._client.partial_update_object_with_http_info( + index_name="theIndexName", + object_id="uniqueID", + attributes_to_update={ + "attributeId": { + "_operation": "Increment", + "value": 2, + }, + }, + ) + + assert _req.path == "/1/indexes/theIndexName/uniqueID/partial" + assert _req.verb == "POST" + assert _req.query_parameters.items() == {}.items() + assert _req.headers.items() >= {}.items() + assert loads(_req.data) == loads( + """{"attributeId":{"_operation":"Increment","value":2}}""" + ) + async def test_remove_user_id_(self): """ removeUserId diff --git a/tests/output/ruby/test/e2e/insights_test.rb b/tests/output/ruby/test/e2e/insights_test.rb index aecfb289f7..925b5eca64 100644 --- a/tests/output/ruby/test/e2e/insights_test.rb +++ b/tests/output/ruby/test/e2e/insights_test.rb @@ -28,7 +28,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"], query_id: "43b15df305339e827f0ac0bdc5ebcaa7" ), @@ -38,7 +38,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"] ) ] @@ -55,7 +55,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"], query_id: "43b15df305339e827f0ac0bdc5ebcaa7" ), @@ -65,7 +65,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"] ) ] diff --git a/tests/output/ruby/test/requests/insights_test.rb b/tests/output/ruby/test/requests/insights_test.rb index 74c121bce0..032c1ec4fd 100644 --- a/tests/output/ruby/test/requests/insights_test.rb +++ b/tests/output/ruby/test/requests/insights_test.rb @@ -338,7 +338,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"], query_id: "43b15df305339e827f0ac0bdc5ebcaa7" ), @@ -348,7 +348,7 @@ def test_push_events1 index: "products", user_token: "user-123456", authenticated_user_token: "user-123456", - timestamp: 1722124800000, + timestamp: 1722384000000, object_ids: ["9780545139700", "9780439784542"] ) ] @@ -361,7 +361,7 @@ def test_push_events1 assert(({}.to_a - req.headers.to_a).empty?, req.headers.to_s) assert_equal( JSON.parse( - "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" + "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" ), JSON.parse(req.body) ) diff --git a/tests/output/ruby/test/requests/search_test.rb b/tests/output/ruby/test/requests/search_test.rb index 43cb2fd744..62b15b0a38 100644 --- a/tests/output/ruby/test/requests/search_test.rb +++ b/tests/output/ruby/test/requests/search_test.rb @@ -1112,7 +1112,7 @@ def test_operation_index2 ) end - # partialUpdateObject + # Partial update with string value def test_partial_update_object req = @client.partial_update_object_with_http_info( "theIndexName", @@ -1131,6 +1131,21 @@ def test_partial_update_object ) end + # Partial update with integer value + def test_partial_update_object1 + req = @client.partial_update_object_with_http_info( + "theIndexName", + "uniqueID", + {attributeId: BuiltInOperation.new(_operation: "Increment", value: 2)} + ) + + assert_equal(:post, req.method) + assert_equal("/1/indexes/theIndexName/uniqueID/partial", req.path) + assert_equal({}.to_a, req.query_params.to_a) + assert(({}.to_a - req.headers.to_a).empty?, req.headers.to_s) + assert_equal(JSON.parse("{\"attributeId\":{\"_operation\":\"Increment\",\"value\":2}}"), JSON.parse(req.body)) + end + # removeUserId def test_remove_user_id req = @client.remove_user_id_with_http_info("uniqueID") diff --git a/tests/output/scala/src/test/scala/algoliasearch/e2e/InsightsTest.scala b/tests/output/scala/src/test/scala/algoliasearch/e2e/InsightsTest.scala index f74237c05d..5c9b0ca93a 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/e2e/InsightsTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/e2e/InsightsTest.scala @@ -49,7 +49,7 @@ class InsightsTestE2E extends AnyFunSuite { index = "products", userToken = "user-123456", authenticatedUserToken = Some("user-123456"), - timestamp = Some(1722124800000L), + timestamp = Some(1722384000000L), objectIDs = Seq("9780545139700", "9780439784542"), queryID = "43b15df305339e827f0ac0bdc5ebcaa7" ), @@ -59,7 +59,7 @@ class InsightsTestE2E extends AnyFunSuite { index = "products", userToken = "user-123456", authenticatedUserToken = Some("user-123456"), - timestamp = Some(1722124800000L), + timestamp = Some(1722384000000L), objectIDs = Seq("9780545139700", "9780439784542") ) ) diff --git a/tests/output/scala/src/test/scala/algoliasearch/requests/InsightsTest.scala b/tests/output/scala/src/test/scala/algoliasearch/requests/InsightsTest.scala index 3fd3990c20..5d65f53686 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/requests/InsightsTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/requests/InsightsTest.scala @@ -574,7 +574,7 @@ class InsightsTest extends AnyFunSuite { index = "products", userToken = "user-123456", authenticatedUserToken = Some("user-123456"), - timestamp = Some(1722124800000L), + timestamp = Some(1722384000000L), objectIDs = Seq("9780545139700", "9780439784542"), queryID = "43b15df305339e827f0ac0bdc5ebcaa7" ), @@ -584,7 +584,7 @@ class InsightsTest extends AnyFunSuite { index = "products", userToken = "user-123456", authenticatedUserToken = Some("user-123456"), - timestamp = Some(1722124800000L), + timestamp = Some(1722384000000L), objectIDs = Seq("9780545139700", "9780439784542") ) ) @@ -597,7 +597,7 @@ class InsightsTest extends AnyFunSuite { assert(res.path == "/1/events") assert(res.method == "POST") val expectedBody = parse( - """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722124800000,"objectIDs":["9780545139700","9780439784542"]}]}""" + """{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1722384000000,"objectIDs":["9780545139700","9780439784542"]}]}""" ) val actualBody = parse(res.body.get) assert(actualBody == expectedBody) diff --git a/tests/output/scala/src/test/scala/algoliasearch/requests/SearchTest.scala b/tests/output/scala/src/test/scala/algoliasearch/requests/SearchTest.scala index edc19ac056..d29b293d29 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/requests/SearchTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/requests/SearchTest.scala @@ -1597,7 +1597,7 @@ class SearchTest extends AnyFunSuite { assert(actualBody == expectedBody) } - test("partialUpdateObject") { + test("Partial update with string value") { val (client, echo) = testClient() val future = client.partialUpdateObject( indexName = "theIndexName", @@ -1606,7 +1606,7 @@ class SearchTest extends AnyFunSuite { "id1" -> AttributeToUpdate("test"), "id2" -> BuiltInOperation( _operation = BuiltInOperationType.withName("AddUnique"), - value = "test2" + value = BuiltInOperationValue("test2") ) ), createIfNotExists = Some(true) @@ -1629,6 +1629,29 @@ class SearchTest extends AnyFunSuite { } } + test("Partial update with integer value1") { + val (client, echo) = testClient() + val future = client.partialUpdateObject( + indexName = "theIndexName", + objectID = "uniqueID", + attributesToUpdate = Map( + "attributeId" -> BuiltInOperation( + _operation = BuiltInOperationType.withName("Increment"), + value = BuiltInOperationValue(2) + ) + ) + ) + + Await.ready(future, Duration.Inf) + val res = echo.lastResponse.get + + assert(res.path == "/1/indexes/theIndexName/uniqueID/partial") + assert(res.method == "POST") + val expectedBody = parse("""{"attributeId":{"_operation":"Increment","value":2}}""") + val actualBody = parse(res.body.get) + assert(actualBody == expectedBody) + } + test("removeUserId") { val (client, echo) = testClient() val future = client.removeUserId( diff --git a/tests/output/swift/Tests/e2e/InsightsTests.swift b/tests/output/swift/Tests/e2e/InsightsTests.swift index 9a9b94cea7..3f1d917f49 100644 --- a/tests/output/swift/Tests/e2e/InsightsTests.swift +++ b/tests/output/swift/Tests/e2e/InsightsTests.swift @@ -65,7 +65,7 @@ final class InsightsClientRequestsTestsE2E: XCTestCase { queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: Int64(1_722_124_800_000) + timestamp: Int64(1_722_384_000_000) )), EventsItems.viewedObjectIDs(ViewedObjectIDs( eventName: "Product Detail Page Viewed", @@ -74,7 +74,7 @@ final class InsightsClientRequestsTestsE2E: XCTestCase { objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: Int64(1_722_124_800_000) + timestamp: Int64(1_722_384_000_000) )), ])) let responseBody = try XCTUnwrap(response.body) diff --git a/tests/output/swift/Tests/requests/InsightsTests.swift b/tests/output/swift/Tests/requests/InsightsTests.swift index 18e97e2f11..a3f8a8dff7 100644 --- a/tests/output/swift/Tests/requests/InsightsTests.swift +++ b/tests/output/swift/Tests/requests/InsightsTests.swift @@ -785,7 +785,7 @@ final class InsightsClientRequestsTests: XCTestCase { queryID: "43b15df305339e827f0ac0bdc5ebcaa7", userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: Int64(1_722_124_800_000) + timestamp: Int64(1_722_384_000_000) )), EventsItems.viewedObjectIDs(ViewedObjectIDs( eventName: "Product Detail Page Viewed", @@ -794,7 +794,7 @@ final class InsightsClientRequestsTests: XCTestCase { objectIDs: ["9780545139700", "9780439784542"], userToken: "user-123456", authenticatedUserToken: "user-123456", - timestamp: Int64(1_722_124_800_000) + timestamp: Int64(1_722_384_000_000) )), ])) let responseBodyData = try XCTUnwrap(response.bodyData) @@ -804,7 +804,7 @@ final class InsightsClientRequestsTests: XCTestCase { let echoResponseBodyJSON = try XCTUnwrap(echoResponseBodyData.jsonString) let expectedBodyData = - "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722124800000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" + "{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}" .data(using: .utf8) let expectedBodyJSON = try XCTUnwrap(expectedBodyData?.jsonString) diff --git a/tests/output/swift/Tests/requests/SearchTests.swift b/tests/output/swift/Tests/requests/SearchTests.swift index f372dcedb0..bab65bbf4b 100644 --- a/tests/output/swift/Tests/requests/SearchTests.swift +++ b/tests/output/swift/Tests/requests/SearchTests.swift @@ -2270,7 +2270,7 @@ final class SearchClientRequestsTests: XCTestCase { XCTAssertNil(echoResponse.queryParameters) } - /// partialUpdateObject + /// Partial update with string value func testPartialUpdateObjectTest() async throws { let configuration = try SearchClientConfiguration( appID: SearchClientRequestsTests.APPLICATION_ID, @@ -2285,7 +2285,10 @@ final class SearchClientRequestsTests: XCTestCase { attributesToUpdate: [ "id1": AttributeToUpdate.string("test"), "id2": AttributeToUpdate - .builtInOperation(BuiltInOperation(operation: BuiltInOperationType.addUnique, value: "test2")), + .builtInOperation(BuiltInOperation( + operation: BuiltInOperationType.addUnique, + value: BuiltInOperationValue.string("test2") + )), ], createIfNotExists: true ) @@ -2313,6 +2316,43 @@ final class SearchClientRequestsTests: XCTestCase { XCTAssertEqual(echoResponse.queryParameters, expectedQueryParametersMap) } + /// Partial update with integer value + func testPartialUpdateObjectTest1() async throws { + let configuration = try SearchClientConfiguration( + appID: SearchClientRequestsTests.APPLICATION_ID, + apiKey: SearchClientRequestsTests.API_KEY + ) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = SearchClient(configuration: configuration, transporter: transporter) + + let response = try await client.partialUpdateObjectWithHTTPInfo( + indexName: "theIndexName", + objectID: "uniqueID", + attributesToUpdate: [ + "attributeId": AttributeToUpdate + .builtInOperation(BuiltInOperation( + operation: BuiltInOperationType.increment, + value: BuiltInOperationValue.int(2) + )), + ] + ) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try XCTUnwrap(echoResponseBodyData.jsonString) + + let expectedBodyData = "{\"attributeId\":{\"_operation\":\"Increment\",\"value\":2}}".data(using: .utf8) + let expectedBodyJSON = try XCTUnwrap(expectedBodyData?.jsonString) + + XCTAssertEqual(echoResponseBodyJSON, expectedBodyJSON) + + XCTAssertEqual(echoResponse.path, "/1/indexes/theIndexName/uniqueID/partial") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryParameters) + } + /// removeUserId func testRemoveUserIdTest() async throws { let configuration = try SearchClientConfiguration(