spartanz / schemaz

A purely-functional library for defining type-safe schemas for algebraic data types, providing free generators, SQL queries, JSON codecs, binary codecs, and migration from this schema definition
https://spartanz.github.io/schemaz
Apache License 2.0
164 stars 18 forks source link

Generic derivation of schemas #48

Open vil1 opened 5 years ago

vil1 commented 5 years ago

Building upon #47, it seems rather obvious that we should be able to automatically derive the schema of any ADT at compile time (as a matter of fact, this gist achieves just that, using shapeless).

Like to #47, this should be provided in the generic (sbt) module, with no impact on the existing API for constructing schemas.

Also, if #34 gets merged before this issue is solved, words must be added in the documentations to stress out the fact that such fully automatic derivation should be used with caution, for it somehow defeats the purpose of having schemas as runtime values (in scenarios where schema evolution is a needed feature, it OK to fully derive schemas at compile time, as long as the application stores the derived schema somewhere at runtime).

sasiharan commented 5 years ago

@vil1, Had a discussion with @GrafBlutwurst about the gist code you shared in the issue for understanding. I will modify this gist code to align with latest schema encoding and raise a PR to take it forward.

vil1 commented 5 years ago

@sasiharan that's great news!

FTR, the mentioned gist is here

Please note that it might be easier to first work on #47 and then use that work to solve this issue (that is, the stuff around the Constructor typeclass in the gist).

Also, I'd prefer we use scalaz-deriving for this instead of shapeless for our generic derivation mechanisms. I'm not yet knowledgeable with it to be able to give you any guidance, but I intend to learn more about it soon (and I can also bring in people who know it well).

sasiharan commented 5 years ago

Agreed that #44 and #47 needs to be addressed before working on this issue. I will also go through scalaz-deriving and see how we can achieve auto derivation of Isos and Schemas.

vil1 commented 5 years ago

Don't worry too much about #44 though, it might take a while to be solved. And if it ever has an impact on your work, I'll take care of it as much as possible.