diff --git a/tapiro/core/src/main/scala/io/buildo/tapiro/TapirMeta.scala b/tapiro/core/src/main/scala/io/buildo/tapiro/TapirMeta.scala index 283ecbb5..540ceede 100644 --- a/tapiro/core/src/main/scala/io/buildo/tapiro/TapirMeta.scala +++ b/tapiro/core/src/main/scala/io/buildo/tapiro/TapirMeta.scala @@ -46,16 +46,17 @@ object TapirMeta { ..${postInputCodecDeclarations} ..${body.map(d => d.copy(mods = mod"override" :: d.mods))} } - } - ..${postInputClassDeclarations} + ..${postInputClassDeclarations} + } } """ - val routeToTapirEndpoint = (route: TapiroRoute) => - q"val ${Pat.Var(Term.Name(route.route.name.tail.mkString))}: ${endpointType(route)} = ${endpointImpl(route)}" + val routeToTapirEndpoint = (tapirEndpointsName: Term.Name) => + (route: TapiroRoute) => + q"val ${Pat.Var(Term.Name(route.route.name.tail.mkString))}: ${endpointType(tapirEndpointsName, route)} = ${endpointImpl(route)}" - private[this] val endpointType = (route: TapiroRoute) => { + private[this] val endpointType = (tapirEndpointsName: Term.Name, route: TapiroRoute) => { val returnType = metarpheusTypeToScalametaType(route.route.returns) val argsType = route.method match { case RouteMethod.GET => @@ -70,7 +71,7 @@ object TapirMeta { .filter(_.tpe == MetarpheusType.Name(authTokenName)) .map(t => metarpheusTypeToScalametaType(t.tpe)) .headOption - val inputType = postInputType(route.route) + val inputType = Type.Select(tapirEndpointsName, postInputType(route.route)) authTokenType match { case Some(t) => Type.Tuple(List(inputType, t)) case None => inputType diff --git a/tapiro/core/src/main/scala/io/buildo/tapiro/Util.scala b/tapiro/core/src/main/scala/io/buildo/tapiro/Util.scala index 57e4ad7e..c6132f9f 100644 --- a/tapiro/core/src/main/scala/io/buildo/tapiro/Util.scala +++ b/tapiro/core/src/main/scala/io/buildo/tapiro/Util.scala @@ -129,7 +129,7 @@ class Util() { requiredPackages.toSet.map(Meta.packageFromList), Term.Name(tapirEndpointsName), Meta.codecsImplicits(routes), - routes.map(TapirMeta.routeToTapirEndpoint), + routes.map(TapirMeta.routeToTapirEndpoint(Term.Name(tapirEndpointsName))), routes.flatMap(TapirMeta.routeClassDeclarations), routes.flatMap(TapirMeta.routeCodecDeclarations), ), diff --git a/tapiro/core/src/test/scala/io/buildo/tapiro/TapiroSuite.scala b/tapiro/core/src/test/scala/io/buildo/tapiro/TapiroSuite.scala index e61dceb7..2197a564 100644 --- a/tapiro/core/src/test/scala/io/buildo/tapiro/TapiroSuite.scala +++ b/tapiro/core/src/test/scala/io/buildo/tapiro/TapiroSuite.scala @@ -53,7 +53,7 @@ class TapiroSuite extends munit.FunSuite { |trait SchoolControllerTapirEndpoints[AuthToken] { | | val create: Endpoint[ - | (CreateRequestPayload, AuthToken), + | (SchoolControllerTapirEndpoints.CreateRequestPayload, AuthToken), | SchoolCreateError, | Unit, | Nothing @@ -79,7 +79,7 @@ class TapiroSuite extends munit.FunSuite { | implicit val createRequestPayloadEncoder: Encoder[CreateRequestPayload] = | deriveEncoder | override val create: Endpoint[ - | (CreateRequestPayload, AuthToken), + | (SchoolControllerTapirEndpoints.CreateRequestPayload, AuthToken), | SchoolCreateError, | Unit, | Nothing @@ -111,8 +111,8 @@ class TapiroSuite extends munit.FunSuite { | override val list: Endpoint[Unit, Unit, List[School], Nothing] = | endpoint.get.in("list").out(jsonBody[List[School]]) | } + | case class CreateRequestPayload(school: School) |} - |case class CreateRequestPayload(school: School) | |/src/main/scala/schools/endpoints/SchoolControllerHttpEndpoints.scala |//----------------------------------------------------------