Map 22+ query params to case class

Hi, I have endpoint with 23+ query params, and of sake of convenience I`ve mapped them to case class.

    query[Option[String]]("q1")
      .and(query[Option[String]]("q2"))
      .and(query[Option[String]]("q3"))
      //....
    .and(query[Option[String]]("q22"))
    .mapTo[EndpointParams]

and it works just fine untill 23rd parameter in list. The error is following:

The arity of the source type doesn't match the arity of the target type

So my question is how to handle such cases(23+ query params mapped to case class)?

This is a limitation in scala (2, in scala 3 it could’ve worked, but tapir is cross built to scala 2 as well)

  1. As a general rule of thumb, you probably want to avoid classes and function with high arity
  2. You can group subsets of parameters, and compose, e.g. something like: p1.and(p2).mapTo[CaseCls1].and(p3.and(p4).mapTo[CaseCls2]).mapTo[CaseCls3]
2 Likes

Yes, we have tuple operations defined only up to 22: https://github.com/softwaremill/tapir/blob/462ca9dfa4ee78c7e8dd0c3422ef779f1e44968c/core/src/main/boilerplate-gen/sttp/tapir/typelevel/TupleOps.scala#L724

As @hochgi mentioned, we could fix this using Scala 3, but so far this code is kept the same for Scala 2/ Scala 3. Not that we wouldn’t welcome a PR changing this, but so far nobody complained :slight_smile:

2 Likes