Skip to content

Commit 2156ac0

Browse files
algolia-botkai687millotp
committed
fix(specs): built-in ops accept also int (generated)
algolia/api-clients-automation#3450 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Kai Welke <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 438e077 commit 2156ac0

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

Sources/Search/Models/BuiltInOperation.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import Foundation
99
/// Update to perform on the attribute.
1010
public struct BuiltInOperation: Codable, JSONEncodable {
1111
public var operation: BuiltInOperationType
12-
/// Value that corresponds to the operation, for example an `Increment` or `Decrement` step, or an `Add` or `Remove`
13-
/// value.
14-
public var value: String
12+
public var value: BuiltInOperationValue
1513

16-
public init(operation: BuiltInOperationType, value: String) {
14+
public init(operation: BuiltInOperationType, value: BuiltInOperationValue) {
1715
self.operation = operation
1816
self.value = value
1917
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on
2+
// https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
import Foundation
5+
#if canImport(Core)
6+
import Core
7+
#endif
8+
9+
public enum BuiltInOperationValue: Codable, JSONEncodable, AbstractEncodable {
10+
case string(String)
11+
case int(Int)
12+
13+
public func encode(to encoder: Encoder) throws {
14+
var container = encoder.singleValueContainer()
15+
switch self {
16+
case let .string(value):
17+
try container.encode(value)
18+
case let .int(value):
19+
try container.encode(value)
20+
}
21+
}
22+
23+
public init(from decoder: Decoder) throws {
24+
let container = try decoder.singleValueContainer()
25+
if let value = try? container.decode(String.self) {
26+
self = .string(value)
27+
} else if let value = try? container.decode(Int.self) {
28+
self = .int(value)
29+
} else {
30+
throw DecodingError.typeMismatch(
31+
Self.Type.self,
32+
.init(
33+
codingPath: decoder.codingPath,
34+
debugDescription: "Unable to decode instance of BuiltInOperationValue"
35+
)
36+
)
37+
}
38+
}
39+
40+
public func GetActualInstance() -> Encodable {
41+
switch self {
42+
case let .string(value):
43+
value as String
44+
case let .int(value):
45+
value as Int
46+
}
47+
}
48+
}
49+
50+
extension BuiltInOperationValue: Equatable {}
51+
extension BuiltInOperationValue: Hashable {}

0 commit comments

Comments
 (0)