Skip to content

Commit 4bc57b1

Browse files
committed
Add RequestBuilder extension, rename to CommonClient+ExplodedParameters
1 parent 3efbe91 commit 4bc57b1

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

boat-scaffold/src/main/java/org/openapitools/codegen/languages/BoatSwift5Codegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void processOpts() {
6868
super.processOpts();
6969
additionalProperties.put("useDBSDataProvider", getLibrary().equals(LIBRARY_DBS));
7070
supportingFiles.add(new SupportingFile("AnyCodable.swift.mustache", sourceFolder, "AnyCodable.swift"));
71-
supportingFiles.add(new SupportingFile("URLEncoding+ExplodedParameters.swift.mustache", sourceFolder, "URLEncoding+ExplodedParameters.swift"));
71+
supportingFiles.add(new SupportingFile("CommonClient+ExplodedParameters.swift.mustache", sourceFolder, "CommonClient+ExplodedParameters.swift"));
7272

7373
if (additionalProperties.containsKey(DEPENDENCY_MANAGEMENT)) {
7474
Object dependenciesAsObject = additionalProperties.get(DEPENDENCY_MANAGEMENT);
Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//
2-
// URLEncoding+ExplodedParameters.swift
3-
// client-common-ios
2+
// CommonClient+ExplodedParameters.swift
43
//
5-
// Created by Mirko Tomic on 16. 6. 2025..
4+
// Generated by openapi-generator
5+
// https://openapi-generator.tech
66
//
77

8+
89
import Foundation
10+
import Backbase
911

1012
/// ArrayParam wrapper for controlling OpenAPI array parameter encoding
1113
public struct ArrayParam {
@@ -28,6 +30,7 @@ public struct ArrayParam {
2830
}
2931
}
3032

33+
// MARK: - URLEncoding Extension with exploded arguments support
3134
public extension URLEncoding {
3235
/// Creates a URL request by encoding parameters with exploded array support
3336
/// and applying them onto an existing request url.
@@ -95,3 +98,39 @@ public extension Array {
9598
ArrayParam(self, exploded: false)
9699
}
97100
}
101+
102+
// MARK: - RequestBuilder Extension with Custom Encoding
103+
public extension RequestBuilder {
104+
105+
/// createURLRequest with exploded support
106+
/// - Parameters:
107+
/// - requestUrl: request URL
108+
/// - method: method
109+
/// - queryParameters: query parameters
110+
/// - bodyParameters: body parameters
111+
/// - bodyType: BodyType
112+
/// - headers: an object of type [String: String]
113+
/// - Returns: URLRequest with exploded parameter support
114+
static func createURLRequestWithExplodedSupport(requestUrl: URL,
115+
method: String,
116+
queryParameters: [String: Any]?,
117+
bodyParameters: [String: Any]?,
118+
bodyType: BodyType,
119+
headers: [String: String] = [:]) throws -> URLRequest {
120+
var modifiedRequest = try URLEncoding.encodeWithExplodedSupport(.init(url: requestUrl), with: queryParameters)
121+
modifiedRequest.httpMethod = method
122+
headers.forEach { modifiedRequest.setValue($0.value, forHTTPHeaderField: $0.key) }
123+
Backbase.authClient().tokens().forEach { modifiedRequest.setValue($0.value, forHTTPHeaderField: $0.key) }
124+
125+
switch bodyType {
126+
case .none:
127+
break
128+
case .json:
129+
modifiedRequest = JSONDataEncoding.encode(modifiedRequest, with: bodyParameters)
130+
case .multipartForm:
131+
modifiedRequest = try FileUploadEncoding.encode(modifiedRequest, with: bodyParameters)
132+
}
133+
134+
return modifiedRequest
135+
}
136+
}

boat-scaffold/src/main/templates/boat-swift5/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ extension {{moduleName}}Client {
273273
headers: headerParameters{{/-first}}{{/headerParams}})
274274
{{/useMsdkSwift}}
275275
{{^useMsdkSwift}}
276-
let request = try ClientCommonGen2.RequestBuilder.createURLRequest(requestUrl: url,
276+
let request = try ClientCommonGen2.RequestBuilder.createURLRequestWithExplodedSupport(requestUrl: url,
277277
method: "{{httpMethod}}",
278278
queryParameters: {{#hasQueryParams}}queryParameters.compactMapValues({ $0 }){{/hasQueryParams}}{{^hasQueryParams}}nil{{/hasQueryParams}},
279279
bodyParameters: parameters,

0 commit comments

Comments
 (0)