diff --git a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache index 03e421b7f10..2857c85889d 100644 --- a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache +++ b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache @@ -30,6 +30,25 @@ open class AlamofireRequestBuilder: RequestBuilder { return Alamofire.SessionManager(configuration: configuration) } + /** + May be overridden by a subclass if you want to control the Content-Type + that is given to an uploaded form part. + + Return nil to use the default behavior (inferring the Content-Type from + the file extension). Return the desired Content-Type otherwise. + */ + open func contentTypeForFormPart(fileURL: URL) -> String? { + return nil + } + + /** + May be overridden by a subclass if you want to control the request + configuration (e.g. to override the cache policy). + */ + open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding) -> DataRequest { + return manager.request(URLString, method: method, parameters: parameters, encoding: encoding) + } + override open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { let managerId:String = UUID().uuidString // Create a new manager for each request to customize its request header @@ -47,7 +66,12 @@ open class AlamofireRequestBuilder: RequestBuilder { for (k, v) in self.parameters! { switch v { case let fileURL as URL: - mpForm.append(fileURL, withName: k) + if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { + mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType) + } + else { + mpForm.append(fileURL, withName: k) + } break case let string as String: mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k) @@ -72,7 +96,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } }) } else { - let request = manager.request(URLString, method: xMethod!, parameters: parameters, encoding: encoding) + let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding) if let onProgressReady = self.onProgressReady { onProgressReady(request.progress) } 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 03e421b7f10..2857c85889d 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -30,6 +30,25 @@ open class AlamofireRequestBuilder: RequestBuilder { return Alamofire.SessionManager(configuration: configuration) } + /** + May be overridden by a subclass if you want to control the Content-Type + that is given to an uploaded form part. + + Return nil to use the default behavior (inferring the Content-Type from + the file extension). Return the desired Content-Type otherwise. + */ + open func contentTypeForFormPart(fileURL: URL) -> String? { + return nil + } + + /** + May be overridden by a subclass if you want to control the request + configuration (e.g. to override the cache policy). + */ + open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding) -> DataRequest { + return manager.request(URLString, method: method, parameters: parameters, encoding: encoding) + } + override open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { let managerId:String = UUID().uuidString // Create a new manager for each request to customize its request header @@ -47,7 +66,12 @@ open class AlamofireRequestBuilder: RequestBuilder { for (k, v) in self.parameters! { switch v { case let fileURL as URL: - mpForm.append(fileURL, withName: k) + if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { + mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType) + } + else { + mpForm.append(fileURL, withName: k) + } break case let string as String: mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k) @@ -72,7 +96,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } }) } else { - let request = manager.request(URLString, method: xMethod!, parameters: parameters, encoding: encoding) + let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding) if let onProgressReady = self.onProgressReady { onProgressReady(request.progress) } 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 03e421b7f10..2857c85889d 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -30,6 +30,25 @@ open class AlamofireRequestBuilder: RequestBuilder { return Alamofire.SessionManager(configuration: configuration) } + /** + May be overridden by a subclass if you want to control the Content-Type + that is given to an uploaded form part. + + Return nil to use the default behavior (inferring the Content-Type from + the file extension). Return the desired Content-Type otherwise. + */ + open func contentTypeForFormPart(fileURL: URL) -> String? { + return nil + } + + /** + May be overridden by a subclass if you want to control the request + configuration (e.g. to override the cache policy). + */ + open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding) -> DataRequest { + return manager.request(URLString, method: method, parameters: parameters, encoding: encoding) + } + override open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { let managerId:String = UUID().uuidString // Create a new manager for each request to customize its request header @@ -47,7 +66,12 @@ open class AlamofireRequestBuilder: RequestBuilder { for (k, v) in self.parameters! { switch v { case let fileURL as URL: - mpForm.append(fileURL, withName: k) + if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { + mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType) + } + else { + mpForm.append(fileURL, withName: k) + } break case let string as String: mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k) @@ -72,7 +96,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } }) } else { - let request = manager.request(URLString, method: xMethod!, parameters: parameters, encoding: encoding) + let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding) if let onProgressReady = self.onProgressReady { onProgressReady(request.progress) } 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 03e421b7f10..2857c85889d 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -30,6 +30,25 @@ open class AlamofireRequestBuilder: RequestBuilder { return Alamofire.SessionManager(configuration: configuration) } + /** + May be overridden by a subclass if you want to control the Content-Type + that is given to an uploaded form part. + + Return nil to use the default behavior (inferring the Content-Type from + the file extension). Return the desired Content-Type otherwise. + */ + open func contentTypeForFormPart(fileURL: URL) -> String? { + return nil + } + + /** + May be overridden by a subclass if you want to control the request + configuration (e.g. to override the cache policy). + */ + open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding) -> DataRequest { + return manager.request(URLString, method: method, parameters: parameters, encoding: encoding) + } + override open func execute(_ completion: @escaping (_ response: Response?, _ error: Error?) -> Void) { let managerId:String = UUID().uuidString // Create a new manager for each request to customize its request header @@ -47,7 +66,12 @@ open class AlamofireRequestBuilder: RequestBuilder { for (k, v) in self.parameters! { switch v { case let fileURL as URL: - mpForm.append(fileURL, withName: k) + if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { + mpForm.append(fileURL, withName: k, fileName: fileURL.lastPathComponent, mimeType: mimeType) + } + else { + mpForm.append(fileURL, withName: k) + } break case let string as String: mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k) @@ -72,7 +96,7 @@ open class AlamofireRequestBuilder: RequestBuilder { } }) } else { - let request = manager.request(URLString, method: xMethod!, parameters: parameters, encoding: encoding) + let request = makeRequest(manager: manager, method: xMethod!, encoding: encoding) if let onProgressReady = self.onProgressReady { onProgressReady(request.progress) }