Package

endpoints

generic

Permalink

package generic

Visibility
  1. Public
  2. All

Type Members

  1. trait JsonSchemas extends algebra.JsonSchemas

    Permalink

    Enriches JsonSchemas with two kinds of operations:

    Enriches JsonSchemas with two kinds of operations:

    - genericJsonSchema[A] derives the JsonSchema of an algebraic data type A; - (field1 :×: field2 :×: …).as[A] builds a tuple of Records and maps it to a case class A

    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")
      ).xmap((User.apply _).tupled)(Function.unlift(User.unapply))
    }

Ungrouped