softwaremill / softwaremill/tapir

Codec don't work with case class contain recursive Seq object

Open
#576 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

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")
      )

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the jsonBody[Seq[Book]] example and compare its Schema derivation with the working jsonBody[List[Book]] case. Reproduce the failure using the recursive Book case class on Scala 2.13.2 and Tapir 0.14.4; done means Seq or Vector outputs compile while retaining support for recursive case classes.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.