softwaremill / softwaremill/tapir
Odd fragility in Tapir/zio-http example
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
Tapir version: 1.2.6
Scala version: 3.2.1
I'm new to both Tapir and ZIO. Please forgive me if I'm missing something obvious!
I've been working on an application using HelloWorldZioHttpServer as an inspiration. I noticed a peculiar fragility. Things are fine if I define my HttpApp in a single expression like
val app0 =
ZioHttpInterpreter().toHttp( helloWorld.zServerLogic(name => ZIO.succeed(s"Hello, $name!") ) )
But the application fails to compile, demanding I provide a ZLayer for scala.Nothing, if I break up the long expression into what I think should produce an identical result:
val app1 =
val se = helloWorld.zServerLogic(name => ZIO.succeed(s"Hello, $name!") )
ZioHttpInterpreter().toHttp( se )
How to reproduce?
Stick this file alone in a directory, and then scala-cli .
It won't compile. Change app1 to app0 in Server.serve(...), then it will, and it works fine!
//> using scala "3.2.1"
//> using lib "com.softwaremill.sttp.tapir::tapir-zio:1.2.6"
//> using lib "com.softwaremill.sttp.tapir::tapir-zio-http-server:1.2.6"
import sttp.tapir.PublicEndpoint
import sttp.tapir.ztapir.*
import sttp.tapir.server.ziohttp.ZioHttpInterpreter
import zio.http.{Http, HttpApp}
import zio.http.{Server, ServerConfig}
import zio.*
object FragileHelloServer extends ZIOAppDefault {
val helloWorld: PublicEndpoint[String, Unit, String, Any] =
endpoint.get
.in("hello")
.in(path[String]("name"))
.out(stringBody)
val app0 =
ZioHttpInterpreter().toHttp( helloWorld.zServerLogic(name => ZIO.succeed(s"Hello, $name!") ) )
val app1 =
val se = helloWorld.zServerLogic(name => ZIO.succeed(s"Hello, $name!") )
ZioHttpInterpreter().toHttp( se )
// starting the server
override def run =
val server = Server.serve(app1)
server.provide(
ServerConfig.live(ServerConfig.default.port(8999)),
Server.live,
).exitCode
}
Additional information
$ java -version
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)
Contributor guide
No contributing guide indexed for this repository
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 with the HelloWorldZioHttpServer.scala example and compare its inline expression with the minimal app0/app1 reproduction. Read the types and inferred ZIO environment around zServerLogic and ZioHttpInterpreter().toHttp, then reproduce the scala-cli compilation failure. Done means the split app1 form compiles and serves the same endpoint without requiring an unexpected ZLayer for scala.Nothing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100