magnolia icon indicating copy to clipboard operation
magnolia copied to clipboard

[question] Derivation differences between Scala 2 and 3

Open cptwunderlich opened this issue 1 year ago • 3 comments

I am currently porting our code base from Scala 2 to 3 and we are heavy users of Tapir.

A lot of semi-auto schema derivations broke after the update. From what I can gather, this affects classes, case classes and final case classing implementing AnyVal.

This scastie snippet does not work with Scala 3, but if you change it to Scala 2.13 (and the tapir dependency ofc.) it compiles: https://scastie.scala-lang.org/BMdIdq6hSRaXrVDNbtjZfg

The code is simply:

import sttp.tapir.Schema

class MyCode(val code: Int) extends AnyVal
val s1: Schema[MyCode] = Schema.derived

The error:

No given instance of type scala.deriving.Mirror.Of[Playground.MyCode] was found for parameter m of method derived in trait SchemaMagnoliaDerivation. Failed to synthesize an instance of type scala.deriving.Mirror.Of[Playground.MyCode]:
	* class MyCode is not a generic product because it is not a case class
	* class MyCode is not a generic sum because it is not a sealed class

My question: Is this to be expected? Is there a way around providing manual schemas for all of these?

cptwunderlich avatar Oct 24 '24 14:10 cptwunderlich

Ah, I guess #527 answers that - it's not implemented yet.

cptwunderlich avatar Oct 24 '24 15:10 cptwunderlich

Ah ... we should get it implemented then :)

adamw avatar Oct 24 '24 15:10 adamw

@cptwunderlich see https://github.com/softwaremill/magnolia/issues/552

adamw avatar Oct 30 '24 12:10 adamw