Skip to content

Commit

Permalink
Merge pull request #350 from buildo/349-tapiro_generation_bug_when
Browse files Browse the repository at this point in the history
#349: Tapiro generation bug when there are duplicate names for commands in different controllers
  • Loading branch information
tpetrucciani authored Mar 8, 2021
2 parents 7d864ab + b1f000f commit fe0f3ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions tapiro/core/src/main/scala/io/buildo/tapiro/TapirMeta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tapiro/core/src/main/scala/io/buildo/tapiro/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
6 changes: 3 additions & 3 deletions tapiro/core/src/test/scala/io/buildo/tapiro/TapiroSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TapiroSuite extends munit.FunSuite {
|trait SchoolControllerTapirEndpoints[AuthToken] {
|
| val create: Endpoint[
| (CreateRequestPayload, AuthToken),
| (SchoolControllerTapirEndpoints.CreateRequestPayload, AuthToken),
| SchoolCreateError,
| Unit,
| Nothing
Expand All @@ -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
Expand Down Expand Up @@ -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
|//----------------------------------------------------------
Expand Down

0 comments on commit fe0f3ba

Please sign in to comment.