package generic
Type Members
-
trait
JsonSchemas extends algebra.JsonSchemas
Enriches JsonSchemas with two kinds of operations:
Enriches JsonSchemas with two kinds of operations:
-
genericJsonSchema[A]
derives theJsonSchema
of an algebraic data typeA
; -(field1 :×: field2 :×: …).as[A]
builds a tuple ofRecord
s and maps it to a case classA
The data type description derivation is based on the underlying field and constructor names.
For instance, consider the following program that derives the description of a case class:
case class User(name: String, age: Int) object User { implicit val schema: JsonSchema[User] = genericJsonSchema[User] }
It is equivalent to the following:
case class User(name: String, age: Int) object User { implicit val schema: JsonSchema[User] = ( field[String]("name") zip field[Int]("age") ).invmap((User.apply _).tupled)(Function.unlift(User.unapply)) }