Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Same Schema names for parametrized classes filled with type aliases #2911

Closed
susliko opened this issue May 23, 2023 · 2 comments
Closed
Assignees

Comments

@susliko
Copy link
Contributor

susliko commented May 23, 2023

Tapir version: 1.4.0

Scala version: 3.3.0-RC6

Describe the bug
Instances of Schema for case classes with its type-parameters filled with type aliases take the name of an alias instead of the name of real type. This results in incorrect openapi schemas

How to reproduce?

//> using scala 3.3.0-RC6
//> using dep com.softwaremill.sttp.tapir::tapir-core:1.4.0
import sttp.tapir.*
import sttp.tapir.generic.auto.*

case class Foo[T](t: T)

object Domain1:
  type Type = Int

object Domain2:
  type Type = String

@main
def main =
  val d1Schema = summon[Schema[Foo[Domain1.Type]]]
  val d2Schema = summon[Schema[Foo[Domain2.Type]]]
  println(d1Schema.name.map(_.show)) // Some(.Foo[Type])
  println(d2Schema.name.map(_.show)) // Some(.Foo[Type])

Additional information
There is a workaround:

  given [T](using ts: Schema[T]): Schema[Foo[T]] =
    Schema
      .derived[Foo[T]]
      .modify(s => s)(s => s.copy(name = s.name.map(n => n.copy(typeParameterShortNames = ts.name.map(_.show).toList))))
@kciesielski
Copy link
Member

Thank you for reporting the issue @susliko. Looks like it's caused by a bug in Magnolia, so I opened a fix PR there softwaremill/magnolia#468

@kciesielski
Copy link
Member

BTW this only happens on Scala 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants