From 5fd6825593880250a78d5587e9f5eb4dc0843ab2 Mon Sep 17 00:00:00 2001 From: Jonas Reichert Date: Fri, 27 Dec 2024 14:42:48 +0100 Subject: [PATCH] generate samples --- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- .../Infrastructure/URLSessionImplementations.swift | 14 +++++++++++++- 11 files changed, 143 insertions(+), 11 deletions(-) diff --git a/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index cf58e2a66eda5..a2e1212a097e9 100644 --- a/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest diff --git a/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift b/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift index 043a2d5d8e215..6acb8d027fb7c 100644 --- a/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift +++ b/samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/URLSessionImplementations.swift @@ -636,12 +636,24 @@ private class FormURLEncoding: ParameterEncoding { var urlRequest = urlRequest var requestBodyComponents = URLComponents() - requestBodyComponents.queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + let queryItems = APIHelper.mapValuesToQueryItems(parameters ?? [:]) + + /// `httpBody` needs to be percent encoded + /// -> https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST + /// "application/x-www-form-urlencoded: [...] Non-alphanumeric characters in both keys and values are percent-encoded" + let percentEncodedQueryItems = queryItems?.compactMap { queryItem in + return URLQueryItem( + name: queryItem.name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? queryItem.name, + value: queryItem.value?.addingPercentEncoding(withAllowedCharacters: .alphanumerics)) + } + requestBodyComponents.queryItems = percentEncodedQueryItems if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil { urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") } + /// We can't use `requestBodyComponents.percentEncodedQuery` since this does NOT percent encode the `+` sign + /// that is why we do the percent encoding manually for each key/value pair urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8) return urlRequest