forked from loafle/openapi-generator-original
[swift5]: support arrays in multipart/form-data (#13383)
* [swift5]: support arrays in multipart/form-data * update samples
This commit is contained in:
parent
072740754b
commit
7ff47dc0bf
@ -103,6 +103,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
|||||||
|
|
||||||
let upload = manager.upload(multipartFormData: { mpForm in
|
let upload = manager.upload(multipartFormData: { mpForm in
|
||||||
for (k, v) in self.parameters! {
|
for (k, v) in self.parameters! {
|
||||||
|
for v in (v as? Array ?? [v]) {
|
||||||
switch v {
|
switch v {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
|
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
|
||||||
@ -122,6 +123,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
|||||||
fatalError("Unprocessable value \(v) with key \(k)")
|
fatalError("Unprocessable value \(v) with key \(k)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, to: URLString, method: xMethod, headers: nil)
|
}, to: URLString, method: xMethod, headers: nil)
|
||||||
.uploadProgress { progress in
|
.uploadProgress { progress in
|
||||||
if let onProgressReady = self.onProgressReady {
|
if let onProgressReady = self.onProgressReady {
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
|||||||
|
|
||||||
let upload = manager.upload(multipartFormData: { mpForm in
|
let upload = manager.upload(multipartFormData: { mpForm in
|
||||||
for (k, v) in self.parameters! {
|
for (k, v) in self.parameters! {
|
||||||
|
for v in (v as? Array ?? [v]) {
|
||||||
switch v {
|
switch v {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
|
if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) {
|
||||||
@ -122,6 +123,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
|||||||
fatalError("Unprocessable value \(v) with key \(k)")
|
fatalError("Unprocessable value \(v) with key \(k)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, to: URLString, method: xMethod, headers: nil)
|
}, to: URLString, method: xMethod, headers: nil)
|
||||||
.uploadProgress { progress in
|
.uploadProgress { progress in
|
||||||
if let onProgressReady = self.onProgressReady {
|
if let onProgressReady = self.onProgressReady {
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
@ -455,6 +455,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
|
||||||
|
|
||||||
for (key, value) in parameters {
|
for (key, value) in parameters {
|
||||||
|
for value in (value as? Array ?? [value]) {
|
||||||
switch value {
|
switch value {
|
||||||
case let fileURL as URL:
|
case let fileURL as URL:
|
||||||
|
|
||||||
@ -511,6 +512,7 @@ private class FormDataEncoding: ParameterEncoding {
|
|||||||
fatalError("Unprocessable value \(value) with key \(key)")
|
fatalError("Unprocessable value \(value) with key \(key)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body = urlRequest.httpBody.orEmpty
|
var body = urlRequest.httpBody.orEmpty
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user