ory / hydra-client-java

Apache License 2.0
26 stars 7 forks source link

Reactive API #5

Closed janekolszak closed 3 years ago

janekolszak commented 3 years ago

Hi, Is there a plan to add reactive api? Otherwise modern Spring webflux servers would need to re implement this project. This seems to be a matter of using another generator. Maybe in a separate repository.

WebClient is reactive: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-client

OpenAPI can generate webclient: https://www.baeldung.com/spring-boot-rest-client-swagger-codegen

Thanks!

aeneasr commented 3 years ago

Jan! Nice to see you still around - we currently don't have plans for that but it would generally be possible to generate SDKs with that client too. What do you not like about the current implementation?

janekolszak commented 3 years ago

Hi, nice to see how you've grown all these years! :)

I'm integrating hydra with a webflux server. But you're right I can generate client myself. Should I take the openapi.yaml file from this repo or is there a newer one somewhere else?

UkonnRa commented 3 years ago

@janekolszak Try this, easy way to warp a callback to Mono:

@Suppress("EmptyFunctionBlock")
private inline fun <reified T> toMono(crossinline fn: (ApiCallback<T>) -> Unit): Mono<T> {
  return Mono.create { sink: MonoSink<T> ->
    try {
      fn(
        object : ApiCallback<T> {
          override fun onFailure(e: ApiException, i: Int, map: Map<String, List<String>>) {
            sink.error(e)
          }

          override fun onSuccess(t: T, i: Int, map: Map<String, List<String>>) {
            sink.success(t)
          }

          override fun onUploadProgress(l: Long, l1: Long, b: Boolean) {}
          override fun onDownloadProgress(l: Long, l1: Long, b: Boolean) {}
        })
    } catch (e: ApiException) {
      sink.error(e)
    }
  }
}
janekolszak commented 3 years ago

Thanks, I ended up copying openapi.yaml and generating webclient API myself. Works like a charm.