Let’s assume I need to make some kind of custom coproduct schema that is also recursive and it is neither wrapped nor it has discriminator - let’s say for API compatibility
example:
model
type Tree[A] = A Or Node[A]
final case class Node[A](vals: List[Tree[A]])
sealed trait Or[+A, +B]
final case class OrLeft[+A, +B](left: A) extends Or[A, B]
final case class OrRight[+A, +B](right: B) extends Or[A, B]
final case class WrappedString(value: String)
final case class WrappedInt(value: Int)
what I want to achieve is a schema that is oneOf: [A, Node[A]]
because it is recursive I ASSUME I need to handle it with refs @line - 42
tho because I am handling it with refs it seems that the schema for Node is not generated / picked up by tapir and we get not resolved ref for that schema.
this is solvable by:
val dummyEndpoints = endpoint
.get
.name("dummy endpoint to make docs work")
.in("dummy")
.in(jsonBody[Node[WrappedString]])
.in(jsonBody[Node[WrappedInt]])
but welp I do not really want to be doing that
so:
is there a better way to handle custom recursive coproduct schemas?
is that need for dummyEndpoint expected / solvable in a better way
@lgmyrek thanks for the Scastie, it’s really helpful The model indeed looks tricky, could you show a few examples of valid JSONs? I assume you need to adjust to some existing API?