From 0768ddcd7c7bd8b03871486fd5f07ac0bb04d65a Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:16:28 +0100 Subject: [PATCH] [swift] support content type application json variants (#18539) * [swift] support content type application json variants * [swift] support content type application json variants --- .../libraries/alamofire/AlamofireImplementations.mustache | 2 +- .../libraries/urlsession/URLSessionImplementations.mustache | 2 +- .../Classes/OpenAPIs/AlamofireImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Sources/PetstoreClient/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- .../Classes/OpenAPIs/URLSessionImplementations.swift | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/swift5/libraries/alamofire/AlamofireImplementations.mustache b/modules/openapi-generator/src/main/resources/swift5/libraries/alamofire/AlamofireImplementations.mustache index 36b4e80c06c2..9ef5937ccc3b 100644 --- a/modules/openapi-generator/src/main/resources/swift5/libraries/alamofire/AlamofireImplementations.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/libraries/alamofire/AlamofireImplementations.mustache @@ -96,7 +96,7 @@ private var managerStore = SynchronizedDictionary() case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = nil diff --git a/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache b/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache index a17db02e6892..eda23b2f65b8 100644 --- a/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache @@ -134,7 +134,7 @@ private var credentialStore = SynchronizedDictionary() case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift index 3ed8fe080f35..0d0e06ee91bb 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift @@ -96,7 +96,7 @@ open class AlamofireRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = nil diff --git a/samples/client/petstore/swift5/anycodableLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/anycodableLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/anycodableLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/anycodableLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index 6d67c0361f6d..ede5a95febac 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ internal class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/validation/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/validation/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/validation/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/validation/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:)) diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift index f05a18087440..e7bbc538c188 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift @@ -134,7 +134,7 @@ open class URLSessionRequestBuilder: RequestBuilder { case .options, .post, .put, .patch, .delete, .trace, .connect: let contentType = headers["Content-Type"] ?? "application/json" - if contentType.hasPrefix("application/json") { + if contentType.hasPrefix("application/") && contentType.contains("json") { encoding = JSONDataEncoding() } else if contentType.hasPrefix("multipart/form-data") { encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))