Skip to content

Commit

Permalink
fix(specs): built-in ops accept also int (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3450

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Kai Welke <kai.welke@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
3 people committed Jul 31, 2024
1 parent 438e077 commit 2156ac0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Sources/Search/Models/BuiltInOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
51 changes: 51 additions & 0 deletions Sources/Search/Models/BuiltInOperationValue.swift
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 2156ac0

Please sign in to comment.