@@ -8,6 +8,7 @@ import sttp.tapir.Codec.JsonCodec
8
8
import sttp .tapir .model .ServerRequest
9
9
import sttp .tapir ._
10
10
import zio ._
11
+ import sttp .tapir .EndpointInput .FixedPath
11
12
12
13
sealed trait HttpInterpreter [- R , E ] { self =>
13
14
protected def endpoints [S ](streams : Streams [S ]): List [
@@ -34,8 +35,8 @@ sealed trait HttpInterpreter[-R, E] { self =>
34
35
def intercept [R1 ](interceptor : Interceptor [R1 , R ]): HttpInterpreter [R1 , E ] =
35
36
HttpInterpreter .Intercepted (self, interceptor)
36
37
37
- def prependInput [BS , S ](prependedInput : EndpointInput [ Unit ]): HttpInterpreter [R , E ] =
38
- HttpInterpreter .Prepended (self, prependedInput )
38
+ def prependPath [BS , S ](path : List [ String ]): HttpInterpreter [R , E ] =
39
+ HttpInterpreter .Prepended (self, path )
39
40
40
41
def configure [R1 ](configurator : Configurator [R1 ]): HttpInterpreter [R & R1 , E ] =
41
42
intercept[R & R1 ](ZLayer .scopedEnvironment[R & R1 & ServerRequest ](configurator *> ZIO .environment[R ]))
@@ -68,12 +69,23 @@ object HttpInterpreter {
68
69
69
70
private case class Prepended [R , E ](
70
71
interpreter : HttpInterpreter [R , E ],
71
- prependedInput : EndpointInput [ Unit ]
72
+ path : List [ String ]
72
73
) extends HttpInterpreter [R , E ] {
73
74
override def endpoints [S ](
74
75
streams : Streams [S ]
75
- ): List [PublicEndpoint [(GraphQLRequest , ServerRequest ), TapirResponse , CalibanResponse [streams.BinaryStream ], S ]] =
76
- interpreter.endpoints(streams).map(_.prependIn(prependedInput))
76
+ ): List [
77
+ PublicEndpoint [(GraphQLRequest , ServerRequest ), TapirResponse , CalibanResponse [streams.BinaryStream ], S ]
78
+ ] = {
79
+ val endpoints = interpreter.endpoints(streams)
80
+ if (path.nonEmpty) {
81
+ val p : List [EndpointInput [Unit ]] = path.map(stringToPath)
82
+ val fixedPath : EndpointInput [Unit ] = p.tail.foldLeft(p.head)(_ / _)
83
+
84
+ endpoints.map(_.prependIn(fixedPath))
85
+ } else {
86
+ endpoints
87
+ }
88
+ }
77
89
78
90
def executeRequest [BS ](
79
91
graphQLRequest : GraphQLRequest ,
0 commit comments