Skip to content

Commit 4e3db96

Browse files
committed
Fix parameter encoding
1 parent 22b1e84 commit 4e3db96

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

templates/swift/Sources/Client.swift.twig

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,28 @@ open class Client {
426426
_ request: inout HTTPClientRequest,
427427
with params: [String: Any?] = [:]
428428
) throws {
429-
let json = try JSONSerialization.data(withJSONObject: params, options: [])
429+
var encodedParams = [String:Any]()
430+
431+
for (key, param) in params {
432+
if param is String
433+
|| param is Int
434+
|| param is Float
435+
|| param is Bool
436+
|| param is [String]
437+
|| param is [Int]
438+
|| param is [Float]
439+
|| param is [Bool]
440+
|| param is [String: Any]
441+
|| param is [Int: Any]
442+
|| param is [Float: Any]
443+
|| param is [Bool: Any]
444+
encodedParams[key] = param
445+
} else {
446+
encodedParams[key] = try! (param as! Encodable).toJson()
447+
}
448+
}
449+
450+
let json = try JSONSerialization.data(withJSONObject: encodedParams, options: [])
430451

431452
request.body = .bytes(json)
432453
}

0 commit comments

Comments
 (0)