I’ve got a rather simple structure that I have to expose as an API, initially I thought of defining these as just case classes but I ended up with over 60 different case classes and that is a pain to test and to generate data for.
I have created this scastie to see the code: Scastie - An interactive playground for Scala. but here’s a little snippet:
final case class Sport(id: Int, name: Option[String]) derives Codec, Schema
final case class Competition(id: Int, name: Option[String]) derives Codec, Schema
type TradingRestriction = Restriction[SportRestriction]
type SportRestriction = Node[Sport, Competition]
enum Restriction[A]:
case All()
case Selections(values: NonEmptySet[A])
final case class Node[A, B](value: A, children: Restriction[B])
The problem I have is that in the NodeSchema I can’t flatten the children
into separate fields in the Node. Do you have any suggestions?