softwaremill / softwaremill/tapir
[BUG] mapOutTo macro fails when generics are involved
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
Tapir version: 1.1.4
Scala version: 2.12.16
Describe the bug
Source: gitter thread
What is the problem?
Code that should be valid fails to compile with an error like:
[error] …/src/main/scala/…/Base.scala:36:14: The type of the tuple field doesn't match the type of the case class field (value payload): T, T
[error] .mapOutTo[MyWrappedResponse[T]]
[error] ^
[error] one error found
How to reproduce?
Defining an endpoint with generic output, e.g:
case class MyWrappedResponse[T](statusCode: Int, payload: T)
def genericResponse[T : JsonCodec : Schema : ClassTag]: PublicEndpoint[Unit, Unit, MyWrappedResponse[T], Any] = endpoint
.get
.in("entity" / implicitly[ClassTag[T]].runtimeClass.getSimpleName)
.out(statusCode)
.mapOut(sc => sc.code)(StatusCode.unsafeApply)
.out(jsonBody[T])
.mapOutTo[MyWrappedResponse[T]]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the genericResponse example with Scala 2.12.16 and inspect the mapOutTo entry point and the related macro diagnostics shown from Base.scala:36. Done means the generic endpoint compiles without the tuple-field type mismatch when mapOutTo[MyWrappedResponse[T]] is used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100