[REQ] Config option to allow for multiple base paths in swift client
Is your feature request related to a problem? Please describe.
We want to use multiple APIs with different base paths, but the base path variable is static with fixed class name.
open class OpenAPIClientAPI {
public static var basePath = "..."
Describe the solution you'd like
A configuration option which would allow us to customize the class name for each API (e.g. MyOpenAPIClientAPI).
Also open to suggestions here 😄 .
Describe alternatives you've considered
Generating separate clients and putting them in separate compile targets. This is highly inconvenient.
Additional context
This seems like it would be a common problem and should not be a hard limitation. Please advise if I have missed an existing way of accomplishing this.
Another option would be to pass the base path to each method call with a default value. We are open to PRs 🙂
Any news about this issue?
I don't think so
@4brunu do you have any suggestion how to solve this problem? I mean if I have multiple base urls?
With the current implementation this is not possible. My suggestion is that someone can create a PR where it's possible to pass the base path to each method call with a default value. This should be easy to do, but it's hard to find time for everything. I can help to review the PR.
...it's possible to pass the base path to each method call with a default value. ...
@4brunu how do you think to make it better? May be to add the parameter with {{projectName}}API to each method call?
e.g. 👇🏻
open class OpenAPIClient {
public static var basePath = "https://base.url"
public static var customHeaders: [String: String] = [:]
public static var credential: URLCredential?
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
public static var apiResponseQueue: DispatchQueue = .main
}
and add this as parameter in each calling:
open class MyAPI {
...
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func SomeFunc(
settings: OpenAPIClient = OpenAPIClient(), // <== Look HERE
myRequest: MyRequest
) async throws -> MyResponse {
....
let localVariablePath = "...localPath..."
let localVariableURLString = settings.basePath + localVariablePath
...
}
That might be a good idea, because different endpoints might require different authentication, diferente headers, etc.