diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/play/Play.scala b/perf-tests/src/main/scala/sttp/tapir/perf/play/Play.scala index 1f9ae57476..c3e576696c 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/play/Play.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/play/Play.scala @@ -89,19 +89,19 @@ object Play { def runServer(routes: ActorSystem => Routes): IO[ServerRunner.KillSwitch] = { implicit lazy val perfActorSystem: ActorSystem = ActorSystem(s"tapir-play") + val playRouter = + Router.from( + List(routes(perfActorSystem)).reduce((a: Routes, b: Routes) => { + val handler: PartialFunction[RequestHeader, Handler] = { case request => + a.applyOrElse(request, b) + } + handler + }) + ) val components = new DefaultPekkoHttpServerComponents { override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(Port), address = "127.0.0.1", mode = Mode.Test) override lazy val actorSystem: ActorSystem = perfActorSystem - override def router: Router = - Router.from( - List(routes(actorSystem)).reduce((a: Routes, b: Routes) => { - val handler: PartialFunction[RequestHeader, Handler] = { case request => - a.applyOrElse(request, b) - } - - handler - }) - ) + override def router: Router = playRouter } IO(components.server).map(server => IO(server.stop())) } diff --git a/server/play-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala b/server/play-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala index 6fca1920ca..10d280168c 100644 --- a/server/play-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala +++ b/server/play-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala @@ -27,7 +27,7 @@ class PlayServerWithContextTest(backend: SttpBackend[IO, Fs2Streams[IO] with Web val components = new DefaultPekkoHttpServerComponents { override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(0), address = "127.0.0.1", mode = Mode.Test) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(_actorSystem.dispatcher)) - override def router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") + override lazy val router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") } val s = components.server val r = Future.successful(()).flatMap { _ => @@ -49,7 +49,7 @@ class PlayServerWithContextTest(backend: SttpBackend[IO, Fs2Streams[IO] with Web val components = new DefaultPekkoHttpServerComponents { override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(0), address = "127.0.0.1", mode = Mode.Test) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(_actorSystem.dispatcher)) - override def router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") + override lazy val router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") } val s = components.server val r = basicRequest diff --git a/server/play-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala b/server/play-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala index 17d4db055c..db6638d025 100644 --- a/server/play-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala +++ b/server/play-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala @@ -48,7 +48,7 @@ class PlayTestServerInterpreter(implicit actorSystem: ActorSystem) initialServerConfig.copy(configuration = customConf.withFallback(initialServerConfig.configuration)) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(PlayTestServerInterpreter.this.actorSystem.dispatcher)) - override def router: Router = + override lazy val router: Router = Router.from( routes.reduce((a: Routes, b: Routes) => { val handler: PartialFunction[RequestHeader, Handler] = { case request => diff --git a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerTest.scala b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerTest.scala index 621feb18d3..c25bd41529 100644 --- a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerTest.scala +++ b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerTest.scala @@ -1,7 +1,6 @@ package sttp.tapir.server.play import akka.actor.ActorSystem -import enumeratum._ import akka.stream.scaladsl.{Flow, Sink, Source} import cats.data.NonEmptyList import cats.effect.{IO, Resource} @@ -17,8 +16,6 @@ import sttp.tapir.server.tests._ import sttp.tapir.tests.{Test, TestSuite} import scala.concurrent.Future -import sttp.tapir.codec.enumeratum.TapirCodecEnumeratum -import sttp.tapir.server.interceptor.decodefailure.DefaultDecodeFailureHandler class PlayServerTest extends TestSuite { diff --git a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala index 88fce1d2de..7e9a169188 100644 --- a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala +++ b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala @@ -27,7 +27,7 @@ class PlayServerWithContextTest(backend: SttpBackend[IO, Fs2Streams[IO] with Web val components = new DefaultAkkaHttpServerComponents { override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(0), address = "127.0.0.1", mode = Mode.Test) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(_actorSystem.dispatcher)) - override def router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") + override lazy val router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") } val s = components.server val r = Future.successful(()).flatMap { _ => @@ -49,7 +49,7 @@ class PlayServerWithContextTest(backend: SttpBackend[IO, Fs2Streams[IO] with Web val components = new DefaultAkkaHttpServerComponents { override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(0), address = "127.0.0.1", mode = Mode.Test) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(_actorSystem.dispatcher)) - override def router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") + override lazy val router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") } val s = components.server val r = basicRequest diff --git a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala index 41af89db0c..dc999c0c96 100644 --- a/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala +++ b/server/play29-server/src/test/scala/sttp/tapir/server/play/PlayTestServerInterpreter.scala @@ -31,8 +31,6 @@ class PlayTestServerInterpreter(implicit actorSystem: ActorSystem) PlayServerInterpreter(serverOptions).toRoutes(es) } - import play.core.server.AkkaHttpServer - override def serverWithStop( routes: NonEmptyList[Routes], gracefulShutdownTimeout: Option[FiniteDuration] @@ -48,7 +46,7 @@ class PlayTestServerInterpreter(implicit actorSystem: ActorSystem) initialServerConfig.copy(configuration = customConf.withFallback(initialServerConfig.configuration)) override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(PlayTestServerInterpreter.this.actorSystem.dispatcher)) - override def router: Router = + override lazy val router: Router = Router.from( routes.reduce((a: Routes, b: Routes) => { val handler: PartialFunction[RequestHeader, Handler] = { case request =>