softwaremill / tapir

Rapid development of self-documenting APIs
https://tapir.softwaremill.com
Apache License 2.0
1.37k stars 422 forks source link

Native artifact for tapir-http4s-client? #2851

Open windymelt opened 1 year ago

windymelt commented 1 year ago

Tapir version: All

Scala version: 3

There is no tapir-http4s-client artifact for Scala Native. Native server module is already provided.

https://mvnrepository.com/artifact/com.softwaremill.sttp.tapir/tapir-http4s-client

If native module provided, we can create native tool which calls http endpoint using http4s.

How to reproduce?

Try to use tapir-http4s-client for native project.

Additional information

adamw commented 1 year ago

Sure, let's add this if possible. Maybe you'd like to attempt creating a PR?

wydra98 commented 1 year ago

I have been working on it and added the necessary dependency in build.sbt to include the native version for tapir-http4s-client. However, this introduced several issues. First, I had to modify the implementation by removing .unsafeRunSync in Http4ClientStreamingTests. Afterwards, I encountered errors of the following type:

[error] Found 77 missing definitions while linking
[error] Not found Top(fs2.Chunk)
[error]     at file:/home/runner/work/tapir/tapir/client/http4s-client/src/main/scala/sttp/tapir/client/http4s/EndpointToHttp4sClient.scala:147
[error] Not found Top(fs2.Chunk$)
....
[error] Not found Top(sttp.capabilities.fs2.Fs2Streams$)
[error]     at file:/home/runner/work/tapir/tapir/client/http4s-client/src/test/scala/sttp/tapir/client/http4s/Http4ClientStreamingTests.scala:1
[error] Not found Member(Top(sttp.capabilities.fs2.Fs2Streams$),D5applyL32sttp.capabilities.fs2.Fs2StreamsEO)
[error]     at file:/home/runner/work/tapir/tapir/client/http4s-client/src/test/scala/sttp/tapir/client/http4s/Http4ClientStreamingTests.scala:11

Interestingly, the http4s server already has the native artifact defined and successfully uses fs2 with the same dependencies (fs2.chunk) without encountering any issues. However, my attempts to modify build.sbt to create client and server dependencies in the same way have been unsuccessful.

Additionaly, the sttp client, specifically the EndpointToSttpClient class, successfully utilizes fs2 and the native implementation. However, implementing a similar approach with the tapir-http4s-client is hard due to differences in types between them.

PR: https://github.com/softwaremill/tapir/pull/2962