Skip to content

[question] Derivation differences between Scala 2 and 3 #550

Open
@cptwunderlich

Description

@cptwunderlich

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions