From 0dffbcbb269b5c18dc5676a6849def34d470d8e3 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 12 Apr 2022 15:13:14 +0300 Subject: [PATCH] fix: array encoding for `QueryStringParameterEncoding` --- CHANGELOG.md | 4 +++ LeadKit.podspec | 2 +- TIFoundationUtils/TIFoundationUtils.podspec | 2 +- TIKeychainUtils/TIKeychainUtils.podspec | 2 +- TIMoyaNetworking/TIMoyaNetworking.podspec | 2 +- .../Encoding/BaseUrlParameterEncoding.swift | 26 +++++++++++++------ .../QueryStringParameterEncoding.swift | 11 ++++---- TINetworking/TINetworking.podspec | 2 +- TISwiftUtils/TISwiftUtils.podspec | 2 +- TITableKitUtils/TITableKitUtils.podspec | 2 +- TITransitions/TITransitions.podspec | 2 +- TIUIElements/TIUIElements.podspec | 2 +- TIUIKitCore/TIUIKitCore.podspec | 2 +- 13 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef0c4a5..998c9766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 1.14.1 + +- **Fix**: Array encoding for `QueryStringParameterEncoding` + ### 1.14.0 - **Add**: [Date] coding methods diff --git a/LeadKit.podspec b/LeadKit.podspec index d0a89c94..31d92a55 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -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" diff --git a/TIFoundationUtils/TIFoundationUtils.podspec b/TIFoundationUtils/TIFoundationUtils.podspec index 053b0b15..e2f65bd7 100644 --- a/TIFoundationUtils/TIFoundationUtils.podspec +++ b/TIFoundationUtils/TIFoundationUtils.podspec @@ -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' } diff --git a/TIKeychainUtils/TIKeychainUtils.podspec b/TIKeychainUtils/TIKeychainUtils.podspec index b94fcffd..a6c0d5e6 100644 --- a/TIKeychainUtils/TIKeychainUtils.podspec +++ b/TIKeychainUtils/TIKeychainUtils.podspec @@ -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' } diff --git a/TIMoyaNetworking/TIMoyaNetworking.podspec b/TIMoyaNetworking/TIMoyaNetworking.podspec index 491060a4..bdc875fb 100644 --- a/TIMoyaNetworking/TIMoyaNetworking.podspec +++ b/TIMoyaNetworking/TIMoyaNetworking.podspec @@ -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' } diff --git a/TINetworking/Sources/Parameters/Encoding/BaseUrlParameterEncoding.swift b/TINetworking/Sources/Parameters/Encoding/BaseUrlParameterEncoding.swift index 7f4878de..5a20ca14 100644 --- a/TINetworking/Sources/Parameters/Encoding/BaseUrlParameterEncoding.swift +++ b/TINetworking/Sources/Parameters/Encoding/BaseUrlParameterEncoding.swift @@ -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(parameters: [String: Parameter]) -> [KeyValueTuple] { var filteredComponents: [KeyValueTuple] = [] 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(parameter: Parameter, forKey key: String) -> [KeyValueTuple] { + 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 [] + } + } } diff --git a/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift b/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift index c7b90531..5eb5b2c9 100644 --- a/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift +++ b/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift @@ -25,10 +25,11 @@ open class QueryStringParameterEncoding: BaseUrlParameterEncoding, ParameterEnco // MARK: - ParameterEncoding open func encode(parameters: [String: Parameter]) -> [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 + } } } diff --git a/TINetworking/TINetworking.podspec b/TINetworking/TINetworking.podspec index 5f25a29f..46326e80 100644 --- a/TINetworking/TINetworking.podspec +++ b/TINetworking/TINetworking.podspec @@ -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' } diff --git a/TISwiftUtils/TISwiftUtils.podspec b/TISwiftUtils/TISwiftUtils.podspec index dedf1a85..756bb15f 100644 --- a/TISwiftUtils/TISwiftUtils.podspec +++ b/TISwiftUtils/TISwiftUtils.podspec @@ -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' } diff --git a/TITableKitUtils/TITableKitUtils.podspec b/TITableKitUtils/TITableKitUtils.podspec index 8bb13778..1dfb0e6f 100644 --- a/TITableKitUtils/TITableKitUtils.podspec +++ b/TITableKitUtils/TITableKitUtils.podspec @@ -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' } diff --git a/TITransitions/TITransitions.podspec b/TITransitions/TITransitions.podspec index 400ebdd9..45336645 100644 --- a/TITransitions/TITransitions.podspec +++ b/TITransitions/TITransitions.podspec @@ -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' } diff --git a/TIUIElements/TIUIElements.podspec b/TIUIElements/TIUIElements.podspec index 9c5d4134..773d9944 100644 --- a/TIUIElements/TIUIElements.podspec +++ b/TIUIElements/TIUIElements.podspec @@ -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' } diff --git a/TIUIKitCore/TIUIKitCore.podspec b/TIUIKitCore/TIUIKitCore.podspec index 65e9203d..96e27162 100644 --- a/TIUIKitCore/TIUIKitCore.podspec +++ b/TIUIKitCore/TIUIKitCore.podspec @@ -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' }