forked from loafle/openapi-generator-original
[swift5] support content types with charsets (#13981)
* enable possibility to add charset to content-type * update samples
This commit is contained in:
@@ -96,9 +96,9 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = nil
|
||||
|
||||
let upload = manager.upload(multipartFormData: { mpForm in
|
||||
@@ -134,7 +134,7 @@ private var managerStore = SynchronizedDictionary<String, Alamofire.Session>()
|
||||
requestTask.set(request: upload)
|
||||
|
||||
self.processRequest(request: upload, managerId, apiResponseQueue, completion)
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = URLEncoding(destination: .httpBody)
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -96,9 +96,9 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = nil
|
||||
|
||||
let upload = manager.upload(multipartFormData: { mpForm in
|
||||
@@ -134,7 +134,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
requestTask.set(request: upload)
|
||||
|
||||
self.processRequest(request: upload, managerId, apiResponseQueue, completion)
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = URLEncoding(destination: .httpBody)
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
@@ -122,11 +122,11 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
case .options, .post, .put, .patch, .delete, .trace, .connect:
|
||||
let contentType = headers["Content-Type"] ?? "application/json"
|
||||
|
||||
if contentType == "application/json" {
|
||||
if contentType.hasPrefix("application/json") {
|
||||
encoding = JSONDataEncoding()
|
||||
} else if contentType == "multipart/form-data" {
|
||||
} else if contentType.hasPrefix("multipart/form-data") {
|
||||
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
|
||||
} else if contentType == "application/x-www-form-urlencoded" {
|
||||
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
|
||||
encoding = FormURLEncoding()
|
||||
} else {
|
||||
fatalError("Unsupported Media Type - \(contentType)")
|
||||
|
||||
Reference in New Issue
Block a user