[Swift] two fixes to latest param mapping code (#4587)

* two fixes: 1) extra ?'s at end of some url's 2) enums not being called out w/ rawValue to get the proper string name

* update samples

* one step closer

* closer implementation
This commit is contained in:
jaz-ah
2017-01-25 09:17:58 -08:00
committed by wing328
parent 2b030a768d
commit f592fdb23e
24 changed files with 396 additions and 344 deletions

View File

@@ -40,12 +40,16 @@ class APIHelper {
}
static func mapValuesToQueryItems(values: [String:Any?]) -> [URLQueryItem] {
return values
static func mapValuesToQueryItems(values: [String:Any?]) -> [URLQueryItem]? {
let returnValues = values
.filter { $0.1 != nil }
.map { (item: (_key: String, _value: Any?)) -> URLQueryItem in
URLQueryItem(name: item._key, value:"\(item._value!)")
}
if returnValues.count == 0 {
return nil
}
return returnValues
}
}

View File

@@ -129,9 +129,9 @@ open class {{classname}}: APIBase {
let url = NSURLComponents(string: URLString)
{{#hasQueryParams}}
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
{{#queryParams}}
"{{paramName}}": {{paramName}}{{#hasMore}}, {{/hasMore}}
{{/queryParams}}
{{#queryParams}}
{{> _param}}{{#hasMore}}, {{/hasMore}}
{{/queryParams}}
])
{{/hasQueryParams}}