tapir icon indicating copy to clipboard operation
tapir copied to clipboard

[BUG] zio-http does not work with multipartBody[T]

Open kmetsalu opened this issue 3 years ago • 2 comments

Tapir version: 0.19-M14

Scala version: Scala 2.13.6

Describe the bug

What is the problem?

zio-http with multipartBody[T] does not work. Server does not respond and it seems that logic is not activated.

How to reproduce?

package example

case class Test(input: String)

object ZioTestApp extends zio.App {

	import zio._
	import zio.magic._
	import zio.logging._
	import sttp.tapir.ztapir._
	import sttp.tapir.generic.auto._
	import zhttp.service.{EventLoopGroup, Server}
	import zhttp.service.server.ServerChannelFactory
	import sttp.tapir.server.ziohttp.ZioHttpInterpreter


	val testEndpoint = endpoint
		.post
		.in("api" / "test")
		.in(multipartBody[Test])
		.out(plainBody[String])

	def testLogic(input: Test) = for {
		_ <- log.info(s"simple call ${input}")
	} yield "ok"

	val testRoute = ZioHttpInterpreter()
		.toHttp(testEndpoint.zServerLogic(testLogic))

	val server = Server.port(9091) ++
		Server.paranoidLeakDetection ++
		Server.app(testRoute)

	val loggingLayer =
		Logging.console() >>>
			Logging.withRootLoggerName("test")

	override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
		server.make
			.use(_ =>
				log.info("server started") *> ZIO.never
			)
			.injectCustom(
				ServerChannelFactory.auto,
				EventLoopGroup.auto(4),
				loggingLayer
			)
			.exitCode
	}

}

Additional information

kmetsalu avatar Nov 10 '21 09:11 kmetsalu

I think it was simply not implemented because of lack of support on zio-http side. See https://github.com/softwaremill/tapir/blob/master/server/zio-http-server/src/main/scala/sttp/tapir/server/ziohttp/ZioHttpRequestBody.scala#L32 (Task.never is not great though, an error would be better).

Ongoing work on zio-http side: https://github.com/dream11/zio-http/pull/515

ghostdogpr avatar Dec 09 '21 14:12 ghostdogpr

I think the right one for the current moment on ZIO side is https://github.com/dream11/zio-http/issues/503

kubinio123 avatar Jan 20 '22 10:01 kubinio123