Skip to content

Commit f9098d5

Browse files
authored
[swift] [urlsession] Fixes crash for uploads with content-type "image/" (#21544)
* Fix image upload for content-type image * update samples * add test case in spec and update samples * update bitrise stack so we get xcpretty 0.4.1 * Revert "add test case in spec and update samples" This reverts commit 92202dd.
1 parent ca8c6d2 commit f9098d5

File tree

24 files changed

+24
-24
lines changed

24 files changed

+24
-24
lines changed

bitrise.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ workflows:
4848
4949
meta:
5050
bitrise.io:
51-
stack: osx-xcode-16.0.x
51+
stack: osx-xcode-16.3.x

modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

modules/openapi-generator/src/main/resources/swift6/libraries/urlsession/URLSessionImplementations.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fileprivate class URLSessionRequestBuilderConfiguration: @unchecked Sendable {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/URLSessionImplementations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal class URLSessionRequestBuilder<T>: RequestBuilder<T> {
140140
encoding = FormDataEncoding(contentTypeForFormPart: contentTypeForFormPart(fileURL:))
141141
} else if contentType.hasPrefix("application/x-www-form-urlencoded") {
142142
encoding = FormURLEncoding()
143-
} else if contentType.hasPrefix("application/octet-stream"){
143+
} else if contentType.hasPrefix("application/octet-stream") || contentType.hasPrefix("image/") {
144144
encoding = OctetStreamEncoding()
145145
} else {
146146
fatalError("Unsupported Media Type - \(contentType)")

0 commit comments

Comments
 (0)