Skip to content

Commit 55cf96e

Browse files
committed
[fix] Refine the implementation of the toParameters method in the container class
Fixed the issue that value conversion to Encodable type failed when there are multiple nested layers in the container.
1 parent b62a664 commit 55cf96e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/RequestInfo/APIParameter.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@ extension APIParameter where Self: Encodable {
2323

2424
extension Array: APIParameter {
2525
public var toParameters: Encodable {
26-
(self as [Any?]).lazy.compactMap { $0 as? Encodable }.map { AnyEncodable($0) }
26+
(self as [Any?])
27+
.lazy
28+
.compactMap {
29+
if let value = $0 as? APIParameter { return value.toParameters }
30+
return $0 as? Encodable
31+
}
32+
.map { AnyEncodable($0) }
2733
}
2834
}
2935

3036
// MARK: - Dictionary
3137

3238
extension Dictionary: APIParameter where Key == String {
3339
public var toParameters: Encodable {
34-
(self as [String: Any?]).compactMapValues { $0 as? Encodable }.mapValues { AnyEncodable($0) }
40+
(self as [String: Any?])
41+
.compactMapValues {
42+
if let value = $0 as? APIParameter { return value.toParameters }
43+
return $0 as? Encodable
44+
}
45+
.mapValues { AnyEncodable($0) }
3546
}
3647
}

0 commit comments

Comments
 (0)