-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animal.scala
26 lines (19 loc) · 984 Bytes
/
Animal.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import io.circe.Codec
import io.circe.generic.AutoDerivation
import io.circe.generic.extras.semiauto.deriveConfiguredCodec
import io.circe.generic.extras.{Configuration => CirceConfiguration}
import sttp.tapir.Schema
import sttp.tapir.generic.{SchemaDerivation, Configuration => TapirConfiguration}
sealed trait Animal {
def name: String
}
object Animal extends AutoDerivation with SchemaDerivation {
implicit val customConfig: CirceConfiguration =
CirceConfiguration.default.withDefaults.withDiscriminator("type")
implicit val codec: Codec[Animal] = deriveConfiguredCodec
implicit val tapirConfig: TapirConfiguration = TapirConfiguration.default.withDiscriminator("type")
// It can't be implicit since recursive derivation fails
implicit val schema: Schema[Animal] = Schema.derived
case class Dog(name: String, training: Boolean, friends: List[Animal]) extends Animal
case class Cat(name: String, favToy: String, friends: List[Animal]) extends Animal
}