Open lgmyrek opened 1 month ago
@lgmyrek thanks for reporting. This one is tricky to tackle. The @newtype
macro generates code like
package object Defs {
type UserId = UserId.Type
object UserId {
type Repr = String
type Base = Any { type UserId$newtype }
trait Tag extends Any
type Type <: Base with Tag
def apply(x: String): UserId = x.asInstanceOf[UserId]
implicit final class Ops$newtype(val $this$: Type) extends AnyVal {
def value: String = $this$.asInstanceOf[String]
}
}
}
I simplified the inner type to String but it doesn't change the fact, that the resolved type name will be UserId.Type
, which in the end results in Map_Type_Type
. I tried to find a way to work around this, but so far without success. Maybe it's the newtype library that could change the Type
type to something like UserIdType
:thinking:
You could try to always name the schemas for new types eg:
implicit def namedSchemaForNewType[A, B: WeakTypeTag](
implicit
ev: Coercible[Schema[A], Schema[B]],
schema: Schema[A],
): Schema[B] = {
val s = symbolOf[B]
ev(schema).name(SName(s.fullName))
}
tho this surely needs some work to also handle newtypes with generic params and I do not know the implications of always naming those for compatibility and other schema interactions
Tapir version: 1.10.8
Scala version: 2.13.14
Describe the bug both Keys and Values are incorrectly named in map schemas - most probably also in other cases
resulting docs for code example:
How to reproduce?
Additional information