OpenAPITools / OpenAPITools/openapi-generator
[REQ] [scala-akka-client] Customize url provider
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Provide url provider wrapper to able customise client with round-robin/service-discovery and similar options based by multiple dynamic urls
Current solution allowed to use only one fixed URL
object UserApi {
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new UserApi(baseUrl)
}
class UserApi(baseUrl: String) {
Describe the solution you'd like
Pass url provider instead of fixed url into ApiInvoker
For example something like this
trait UrlProvider {
def execute[F[_], T)(f: String => F[T]): F[T]
}
# Simple implementation
class SingleUrlProvider extends UrlProvider {
override def execute .. = {
f("https://petstore.swagger.io/v2")
}
}
and execution (in ApiInvoiker):
def execute[T: Manifest](apiRequest: ApiRequest[T]) = {
urlProvider.execute { url =>
val request = createRequest(makeUri(url, apiRequest), apiRequest)
request.response { ... }.send()
}
}
So i can pass my own url providers implementation and manage urls externally something like:
# choose random server to query
RandomUrlProvider extends UrlProvider {
private def getUrl() = {
val random = new scala.util.Random
val urls = List("https://petstore.swagger.io/v2", "https://another.petstore.swagger.io/v2")
urls(random.nextInt(urls.length))
}
override def execute[T](f: (String) => Future[T]): Future[T] = {
f(getUrl())
}
}
Describe alternatives you've considered
I prefer to implement provider against ApiInvoker, but current implementation let define url on each Api. Which way is better?
Additional context
This feature will allow to build fault-tolerant clients and keep generated version slim and clean from custom stuff
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the scala-akka-client ApiInvoker and the generated UserApi classes shown in the issue. Trace how the fixed base URL reaches request creation, then determine how an injectable URL provider could support dynamic URLs while retaining the simple single-URL case. Done means the client can accept custom provider implementations for request execution without requiring generated APIs to manage provider logic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100