diff --git a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache index 108eea11c25..fd981a05b05 100644 --- a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache +++ b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache @@ -13,8 +13,38 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory { } } +private struct SynchronizedDictionary { + + private var dictionary = [K: V]() + private let queue = DispatchQueue( + label: "SynchronizedDictionary", + qos: DispatchQoS.userInitiated, + attributes: [DispatchQueue.Attributes.concurrent], + autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit, + target: nil + ) + + public subscript(key: K) -> V? { + get { + var value: V? + + queue.sync { + value = self.dictionary[key] + } + + return value + } + set { + queue.sync(flags: DispatchWorkItemFlags.barrier) { + self.dictionary[key] = newValue + } + } + } + +} + // Store manager to retain its reference -private var managerStore: [String: Alamofire.SessionManager] = [:] +private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { @@ -112,7 +142,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } let cleanupRequest = { - _ = managerStore.removeValue(forKey: managerId) + managerStore[managerId] = nil } let validatedRequest = request.validate() diff --git a/samples/client/petstore/swift3/default/.swagger-codegen/VERSION b/samples/client/petstore/swift3/default/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/swift3/default/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 108eea11c25..fd981a05b05 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -13,8 +13,38 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory { } } +private struct SynchronizedDictionary { + + private var dictionary = [K: V]() + private let queue = DispatchQueue( + label: "SynchronizedDictionary", + qos: DispatchQoS.userInitiated, + attributes: [DispatchQueue.Attributes.concurrent], + autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit, + target: nil + ) + + public subscript(key: K) -> V? { + get { + var value: V? + + queue.sync { + value = self.dictionary[key] + } + + return value + } + set { + queue.sync(flags: DispatchWorkItemFlags.barrier) { + self.dictionary[key] = newValue + } + } + } + +} + // Store manager to retain its reference -private var managerStore: [String: Alamofire.SessionManager] = [:] +private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { @@ -112,7 +142,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } let cleanupRequest = { - _ = managerStore.removeValue(forKey: managerId) + managerStore[managerId] = nil } let validatedRequest = request.validate() diff --git a/samples/client/petstore/swift3/promisekit/.swagger-codegen/VERSION b/samples/client/petstore/swift3/promisekit/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/swift3/promisekit/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 108eea11c25..fd981a05b05 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -13,8 +13,38 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory { } } +private struct SynchronizedDictionary { + + private var dictionary = [K: V]() + private let queue = DispatchQueue( + label: "SynchronizedDictionary", + qos: DispatchQoS.userInitiated, + attributes: [DispatchQueue.Attributes.concurrent], + autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit, + target: nil + ) + + public subscript(key: K) -> V? { + get { + var value: V? + + queue.sync { + value = self.dictionary[key] + } + + return value + } + set { + queue.sync(flags: DispatchWorkItemFlags.barrier) { + self.dictionary[key] = newValue + } + } + } + +} + // Store manager to retain its reference -private var managerStore: [String: Alamofire.SessionManager] = [:] +private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { @@ -112,7 +142,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } let cleanupRequest = { - _ = managerStore.removeValue(forKey: managerId) + managerStore[managerId] = nil } let validatedRequest = request.validate() diff --git a/samples/client/petstore/swift3/rxswift/.swagger-codegen/VERSION b/samples/client/petstore/swift3/rxswift/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/swift3/rxswift/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 108eea11c25..fd981a05b05 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -13,8 +13,38 @@ class AlamofireRequestBuilderFactory: RequestBuilderFactory { } } +private struct SynchronizedDictionary { + + private var dictionary = [K: V]() + private let queue = DispatchQueue( + label: "SynchronizedDictionary", + qos: DispatchQoS.userInitiated, + attributes: [DispatchQueue.Attributes.concurrent], + autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency.inherit, + target: nil + ) + + public subscript(key: K) -> V? { + get { + var value: V? + + queue.sync { + value = self.dictionary[key] + } + + return value + } + set { + queue.sync(flags: DispatchWorkItemFlags.barrier) { + self.dictionary[key] = newValue + } + } + } + +} + // Store manager to retain its reference -private var managerStore: [String: Alamofire.SessionManager] = [:] +private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { @@ -112,7 +142,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } let cleanupRequest = { - _ = managerStore.removeValue(forKey: managerId) + managerStore[managerId] = nil } let validatedRequest = request.validate()