From 17a639be75d13985c4b1fcede1b2a7716c2cd238 Mon Sep 17 00:00:00 2001 From: Landschaft Date: Fri, 3 Jun 2016 13:12:07 +0200 Subject: [PATCH] [Swift] #3036 Make APIHelper.convertBoolToString return nil for nil input. This will prevent the creation of an empty body for GET requests. --- .../main/resources/swift/APIHelper.mustache | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/swift/APIHelper.mustache b/modules/swagger-codegen/src/main/resources/swift/APIHelper.mustache index 7041709f365..23e727b6b54 100644 --- a/modules/swagger-codegen/src/main/resources/swift/APIHelper.mustache +++ b/modules/swagger-codegen/src/main/resources/swift/APIHelper.mustache @@ -19,18 +19,19 @@ class APIHelper { return destination } - static func convertBoolToString(source: [String: AnyObject]?) -> [String:AnyObject] { + static func convertBoolToString(source: [String: AnyObject]?) -> [String:AnyObject]? { + guard let source = source else { + return nil + } var destination = [String:AnyObject]() let theTrue = NSNumber(bool: true) let theFalse = NSNumber(bool: false) - if (source != nil) { - for (key, value) in source! { - switch value { - case let x where x === theTrue || x === theFalse: - destination[key] = "\(value as! Bool)" - default: - destination[key] = value - } + for (key, value) in source { + switch value { + case let x where x === theTrue || x === theFalse: + destination[key] = "\(value as! Bool)" + default: + destination[key] = value } } return destination