fix: array encoding for `QueryStringParameterEncoding`

This commit is contained in:
Ivan Smolin 2022-04-12 15:13:14 +03:00
parent 9a3d061c63
commit 0dffbcbb26
13 changed files with 38 additions and 23 deletions

View File

@ -1,5 +1,9 @@
# Changelog
### 1.14.1
- **Fix**: Array encoding for `QueryStringParameterEncoding`
### 1.14.0
- **Add**: [Date] coding methods

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LeadKit"
s.version = "1.14.0"
s.version = "1.14.1"
s.summary = "iOS framework with a bunch of tools for rapid development"
s.homepage = "https://github.com/TouchInstinct/LeadKit"
s.license = "Apache License, Version 2.0"

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TIFoundationUtils'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Set of helpers for Foundation framework classes.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TIKeychainUtils'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Set of helpers for Keychain classes.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TIMoyaNetworking'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Moya + Swagger network service.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -23,25 +23,35 @@
import Alamofire
open class BaseUrlParameterEncoding {
private let encoding: URLEncoding = .queryString
private let encoding: URLEncoding
public init() {}
public init(encoding: URLEncoding = .queryString) {
self.encoding = encoding
}
open func encode<L: ParameterLocation>(parameters: [String: Parameter<L>]) -> [KeyValueTuple<String, String>] {
var filteredComponents: [KeyValueTuple<String, String>] = []
for key in parameters.keys.sorted(by: <) {
guard let parameter = parameters[key], let value = parameter.value else {
guard let parameter = parameters[key] else {
continue
}
let components = encoding.queryComponents(fromKey: key, value: value)
// filter components with empty values if parameter doesn't allow empty value
.filter { !$0.1.isEmpty || parameter.allowEmptyValue }
filteredComponents.append(contentsOf: components)
filteredComponents.append(contentsOf: encode(parameter: parameter, forKey: key))
}
return filteredComponents
}
open func encode<L: ParameterLocation>(parameter: Parameter<L>, forKey key: String) -> [KeyValueTuple<String, String>] {
if let value = parameter.value {
return encoding.queryComponents(fromKey: key, value: value)
// filter components with empty values if parameter doesn't allow empty value
.filter { !$0.1.isEmpty || parameter.allowEmptyValue }
} else if parameter.allowEmptyValue {
return [KeyValueTuple(key, .init())]
} else {
return []
}
}
}

View File

@ -25,10 +25,11 @@ open class QueryStringParameterEncoding: BaseUrlParameterEncoding, ParameterEnco
// MARK: - ParameterEncoding
open func encode(parameters: [String: Parameter<LocationQuery>]) -> [String: Any] {
let nonEmptyValueKeys = Set(super.encode(parameters: parameters).map { $0.key })
return parameters
.filter { nonEmptyValueKeys.contains($0.key) }
.compactMapValues { $0.value }
parameters.filter {
!encode(parameter: $0.value, forKey: $0.key).isEmpty
}
.compactMapValues {
$0.value
}
}
}

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TINetworking'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Swagger-frendly networking layer helpers.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TISwiftUtils'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Bunch of useful helpers for Swift development.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TITableKitUtils'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Set of helpers for TableKit classes.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TITransitions'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Set of custom transitions to present controller. '
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TIUIElements'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Bunch of useful protocols and views.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TIUIKitCore'
s.version = '1.14.0'
s.version = '1.14.1'
s.summary = 'Core UI elements: protocols, views and helpers.'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }