diff --git a/Sources/Search/Models/BuiltInOperation.swift b/Sources/Search/Models/BuiltInOperation.swift index 8d3f19af..7556afb9 100644 --- a/Sources/Search/Models/BuiltInOperation.swift +++ b/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/Sources/Search/Models/BuiltInOperationValue.swift b/Sources/Search/Models/BuiltInOperationValue.swift new file mode 100644 index 00000000..07ad6ae8 --- /dev/null +++ b/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 {}