tapir
tapir copied to clipboard
Codec don't work with case class contain recursive Seq object
Tapir version: 0.14.4
Scala version: 2.13.2
Describe the bug
Tapir Codec don't work on case class which contains recursive Seq object and the jsonBody output is Seq/Vector object
How to reproduce?
First, we have a Book case class which contains a recursive Seq[Book]
case class Book(title: String, year: Int, entities: Seq[Book])
Next Step, we try to define endpoint and output is Seq[Book]
val bookEndpoint: Endpoint[String, Unit, Seq[Book], Stream[IO, Byte]] =
endpoint.get
.in("books" / path[String]("bookId"))
.out(
jsonBody[Seq[Book]]
.description("Corresponding book")
)
Then the error will come up at jsonBody[Seq[Book]]
Error:(57, 17) could not find implicit value for evidence parameter of type sttp.tapir.Schema[Seq[com.yahoo.astra.global.knowledge.serving.services.Book]]
jsonBody[Seq[Book]]
However, it work when you change the output from Seq/Vector to List
val bookEndpoint: Endpoint[String, Unit, List[Book], Stream[IO, Byte]] =
endpoint.get
.in("books" / path[String]("bookId"))
.out(
jsonBody[List[Book]]
.description("Corresponding book")
)
For some weird reason implicit def schemaForIterable[T: Schema, C[X] <: Iterable[X]]: Schema[C[T]] = implicitly[Schema[T]].asIterable[C] only works for lists, but not for seq/vector. No idea why.