Closed satorg closed 1 year ago
Typeclass derivation doesn't give access to def
, only case class fields so this is not supported.
The workaround is to make a custom Schema
for your interface that can use the auto-generated one but override the description.
@ghostdogpr thank you for the clarification!
Typeclass derivation doesn't give access to def, only case class fields
Do I understand correctly, that it is a restriction imposed by an upstream library (I guess Magnolia or something)?
Even if it cannot be entirely supported, I suppose the experience can be improved quite a bit. Specifically, I'm thinking about two assumptions that IMO should be feasible to implement:
If the same method in every type implementing some interface has the same description, then copy the description into the corresponding method of the interface (because most likely the description was simply copied among all types and their interface all together).
If the same method in different types has different descriptions, then discard the description in the corresponding method of their interface.
It would not be perfect of course, but I believe it would be way more intuitive to users and could support more real use cases without falling into manual schema adjustments.
Also I feel it would be really helpful to have a new paragraph in the Schemas chapter (e.g. "Known Limitations") where users could read about issues like this one.
Do I understand correctly, that it is a restriction imposed by an upstream library (I guess Magnolia or something)?
Yep, that's right: Magnolia on Scala 2 and direct typeclass derivation on Scala 3.
I agree with the heuristic proposed, and it should not be hard to implement.
Consider a snippet:
Expected output:
Actual output: