Schema

zio.blocks.schema.Schema
See theSchema companion class

Derivation with derived, the built-in schemas of standard types (primitives, java.time types, UUID, Currency, options, collections, Either and DynamicValue), and fromJsonSchema.

Attributes

Companion
class
Source
Schema.scala
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Show all
Self type
Schema.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def apply[A](implicit schema: Schema[A]): Schema[A]

Returns the implicit schema of A, as in Schema[Book].

Returns the implicit schema of A, as in Schema[Book].

Attributes

Source
Schema.scala
def fromJsonSchema(jsonSchema: JsonSchema): Schema[Json]

Builds a Schema[Json] from jsonSchema. Decoding with it, for example with its jsonCodec, checks each value against jsonSchema and returns Left when the check fails. The check runs at decode time, not when the schema is built.

Builds a Schema[Json] from jsonSchema. Decoding with it, for example with its jsonCodec, checks each value against jsonSchema and returns Left when the check fails. The check runs at decode time, not when the schema is built.

Every property listed in "properties" is treated as required, even when "required" leaves it out: an object without it fails to decode with missing required field. Decode errors carry an extra .wrapped step, from the wrapper that runs the check, and a failed check is reported at that step, with the place inside the JSON value only in the message text, as in the example below.

import zio.blocks.schema.json.JsonSchema

val jsonSchema = JsonSchema
 .parse("""{"type":"object","properties":{"title":{"type":"string","minLength":1}},"required":["title"]}""")
 .fold(e => throw e, identity)
val books = Schema.fromJsonSchema(jsonSchema)

val valid   = books.jsonCodec.decode("""{"title":"Zionomicon"}""").isRight // true
val invalid = books.jsonCodec.decode("""{"title":""}""")
// Left(zio.blocks.schema.SchemaError: String length 0 is less than minLength 1 at: .title at: .wrapped)

Attributes

See also
Source
Schema.scala

Inherited methods

inline def derived[A]: Schema[A]

Derives the schema of A at compile time. It supports case classes and other classes whose constructor parameters are vals or vars, sealed traits and sealed abstract classes with their cases, case objects, options, arrays and collections, and ZIO Prelude newtypes. On Scala 3 it also supports enums, union types, generic and named tuples, opaque types and Neotype newtypes, and derives Schema calls it.

Derives the schema of A at compile time. It supports case classes and other classes whose constructor parameters are vals or vars, sealed traits and sealed abstract classes with their cases, case objects, options, arrays and collections, and ZIO Prelude newtypes. On Scala 3 it also supports enums, union types, generic and named tuples, opaque types and Neotype newtypes, and derives Schema calls it.

For each field or case type it uses the implicit Schema in scope when there is one, so an implicit val of type Schema[LocalDate] changes how every LocalDate field is represented, in every format. An implicit codec in scope, such as a JsonCodec, is not used. Annotations that extend Modifier.Term on fields and cases, and Modifier.Reflect on the type, become modifiers of the schema.

Derivation fails to compile for a type it cannot derive (Cannot derive schema for ...), and for a field marked transient or encodeTransient that has no default value and is neither an Option nor a collection.

Deriving, from inside a class, a sealed trait declared in that class whose case classes sit in the trait's companion crashes the compiler. Derive the trait's schema in its companion instead, or declare the model in an object.

sealed trait Format
object Format {
 case object Hardcover                  extends Format
 final case class Ebook(sizeMb: Double) extends Format
 implicit val schema: Schema[Format] = Schema.derived
}

final case class Book(format: Format, title: String)
object Book {
 implicit val schema: Schema[Book] = Schema.derived
}

val json = Schema[Book].jsonCodec.encodeToString(Book(Format.Ebook(2.5), "Zionomicon"))
// {"format":{"Ebook":{"sizeMb":2.5}},"title":"Zionomicon"}

Attributes

See also
Inherited from:
SchemaCompanionVersionSpecific
Source
SchemaCompanionVersionSpecific.scala

Implicits

Implicits

implicit val bigDecimal: Schema[BigDecimal]

The schema of BigDecimal.

The schema of BigDecimal.

Attributes

Source
Schema.scala
implicit val bigInt: Schema[BigInt]

The schema of BigInt.

The schema of BigInt.

Attributes

Source
Schema.scala
implicit val boolean: Schema[Boolean]

The schema of Boolean.

The schema of Boolean.

Attributes

Source
Schema.scala
implicit val byte: Schema[Byte]

The schema of Byte.

The schema of Byte.

Attributes

Source
Schema.scala
implicit val char: Schema[Char]

The schema of Char.

The schema of Char.

Attributes

Source
Schema.scala
implicit def chunk[A](implicit element: Schema[A]): Schema[Chunk[A]]

The schema of Chunk[A], built from the schema of its elements.

The schema of Chunk[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit def chunkMap[A, B](implicit key: Schema[A], value: Schema[B]): Schema[ChunkMap[A, B]]

The schema of ChunkMap[A, B], built from the schemas of its keys and values.

The schema of ChunkMap[A, B], built from the schemas of its keys and values.

Attributes

Source
Schema.scala
implicit val currency: Schema[Currency]

The schema of java.util.Currency.

The schema of java.util.Currency.

Attributes

Source
Schema.scala
implicit val dayOfWeek: Schema[DayOfWeek]

The schema of java.time.DayOfWeek.

The schema of java.time.DayOfWeek.

Attributes

Source
Schema.scala
implicit val double: Schema[Double]

The schema of Double.

The schema of Double.

Attributes

Source
Schema.scala
implicit val duration: Schema[Duration]

The schema of java.time.Duration.

The schema of java.time.Duration.

Attributes

Source
Schema.scala
implicit val dynamic: Schema[DynamicValue]

The schema of DynamicValue, which accepts any dynamic value.

The schema of DynamicValue, which accepts any dynamic value.

Attributes

Source
Schema.scala
implicit def either[A, B](implicit left: Schema[A], right: Schema[B]): Schema[Either[A, B]]

Provides a schema for Either[A, B] when schemas for both value types are available.

Provides a schema for Either[A, B] when schemas for both value types are available.

Primitive values and primitive-backed wrappers retain their specialized register layouts in both branches.

Type parameters

A

the left value type

B

the right value type

Value parameters

left

the schema for left values

right

the schema for right values

Attributes

Returns

a schema for Either[A, B]

Example
val schema = Schema[Either[String, Int]]
Source
Schema.scala
implicit val float: Schema[Float]

The schema of Float.

The schema of Float.

Attributes

Source
Schema.scala
implicit def indexedSeq[A](implicit element: Schema[A]): Schema[IndexedSeq[A]]

The schema of IndexedSeq[A], built from the schema of its elements.

The schema of IndexedSeq[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit val instant: Schema[Instant]

The schema of java.time.Instant.

The schema of java.time.Instant.

Attributes

Source
Schema.scala
implicit val int: Schema[Int]

The schema of Int.

The schema of Int.

Attributes

Source
Schema.scala
implicit def list[A](implicit element: Schema[A]): Schema[List[A]]

The schema of List[A], built from the schema of its elements.

The schema of List[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit val localDate: Schema[LocalDate]

The schema of java.time.LocalDate.

The schema of java.time.LocalDate.

Attributes

Source
Schema.scala

The schema of java.time.LocalDateTime.

The schema of java.time.LocalDateTime.

Attributes

Source
Schema.scala
implicit val localTime: Schema[LocalTime]

The schema of java.time.LocalTime.

The schema of java.time.LocalTime.

Attributes

Source
Schema.scala
implicit val long: Schema[Long]

The schema of Long.

The schema of Long.

Attributes

Source
Schema.scala
implicit def map[A, B](implicit key: Schema[A], value: Schema[B]): Schema[Map[A, B]]

The schema of an immutable Map[A, B], built from the schemas of its keys and values.

The schema of an immutable Map[A, B], built from the schemas of its keys and values.

Attributes

Source
Schema.scala
implicit def maybe[A <: AnyRef](implicit element: Schema[A]): Schema[Maybe[A]]

The schema of Maybe[A] for a reference type A: a variant with the cases Absent and Present.

The schema of Maybe[A] for a reference type A: a variant with the cases Absent and Present.

Maybes of primitive types have their own instances, such as maybeInt.

Attributes

Source
Schema.scala
implicit val maybeBoolean: Schema[Maybe[Boolean]]

The schema of Maybe[Boolean], with a Present binding specialized for Boolean.

The schema of Maybe[Boolean], with a Present binding specialized for Boolean.

Attributes

Source
Schema.scala
implicit val maybeByte: Schema[Maybe[Byte]]

The schema of Maybe[Byte], with a Present binding specialized for Byte.

The schema of Maybe[Byte], with a Present binding specialized for Byte.

Attributes

Source
Schema.scala
implicit val maybeChar: Schema[Maybe[Char]]

The schema of Maybe[Char], with a Present binding specialized for Char.

The schema of Maybe[Char], with a Present binding specialized for Char.

Attributes

Source
Schema.scala
implicit val maybeDouble: Schema[Maybe[Double]]

The schema of Maybe[Double], with a Present binding specialized for Double.

The schema of Maybe[Double], with a Present binding specialized for Double.

Attributes

Source
Schema.scala
implicit val maybeFloat: Schema[Maybe[Float]]

The schema of Maybe[Float], with a Present binding specialized for Float.

The schema of Maybe[Float], with a Present binding specialized for Float.

Attributes

Source
Schema.scala
implicit val maybeInt: Schema[Maybe[Int]]

The schema of Maybe[Int], with a Present binding specialized for Int.

The schema of Maybe[Int], with a Present binding specialized for Int.

Attributes

Source
Schema.scala
implicit val maybeLong: Schema[Maybe[Long]]

The schema of Maybe[Long], with a Present binding specialized for Long.

The schema of Maybe[Long], with a Present binding specialized for Long.

Attributes

Source
Schema.scala
implicit val maybeShort: Schema[Maybe[Short]]

The schema of Maybe[Short], with a Present binding specialized for Short.

The schema of Maybe[Short], with a Present binding specialized for Short.

Attributes

Source
Schema.scala
implicit val maybeUnit: Schema[Maybe[Unit]]

The schema of Maybe[Unit], with a Present binding specialized for Unit.

The schema of Maybe[Unit], with a Present binding specialized for Unit.

Attributes

Source
Schema.scala
implicit val month: Schema[Month]

The schema of java.time.Month.

The schema of java.time.Month.

Attributes

Source
Schema.scala
implicit val monthDay: Schema[MonthDay]

The schema of java.time.MonthDay.

The schema of java.time.MonthDay.

Attributes

Source
Schema.scala

The schema of java.time.OffsetDateTime.

The schema of java.time.OffsetDateTime.

Attributes

Source
Schema.scala
implicit val offsetTime: Schema[OffsetTime]

The schema of java.time.OffsetTime.

The schema of java.time.OffsetTime.

Attributes

Source
Schema.scala
implicit def option[A <: AnyRef](implicit element: Schema[A]): Schema[Option[A]]

The schema of Option[A] for a reference type A: a variant with the cases None and Some.

The schema of Option[A] for a reference type A: a variant with the cases None and Some.

Options of primitive types have their own instances, such as optionInt.

Attributes

Source
Schema.scala
implicit val optionBoolean: Schema[Option[Boolean]]

The schema of Option[Boolean], with a Some binding specialized for Boolean.

The schema of Option[Boolean], with a Some binding specialized for Boolean.

Attributes

Source
Schema.scala
implicit val optionByte: Schema[Option[Byte]]

The schema of Option[Byte], with a Some binding specialized for Byte.

The schema of Option[Byte], with a Some binding specialized for Byte.

Attributes

Source
Schema.scala
implicit val optionChar: Schema[Option[Char]]

The schema of Option[Char], with a Some binding specialized for Char.

The schema of Option[Char], with a Some binding specialized for Char.

Attributes

Source
Schema.scala
implicit val optionDouble: Schema[Option[Double]]

The schema of Option[Double], with a Some binding specialized for Double.

The schema of Option[Double], with a Some binding specialized for Double.

Attributes

Source
Schema.scala
implicit val optionFloat: Schema[Option[Float]]

The schema of Option[Float], with a Some binding specialized for Float.

The schema of Option[Float], with a Some binding specialized for Float.

Attributes

Source
Schema.scala
implicit val optionInt: Schema[Option[Int]]

The schema of Option[Int], with a Some binding specialized for Int.

The schema of Option[Int], with a Some binding specialized for Int.

Attributes

Source
Schema.scala
implicit val optionLong: Schema[Option[Long]]

The schema of Option[Long], with a Some binding specialized for Long.

The schema of Option[Long], with a Some binding specialized for Long.

Attributes

Source
Schema.scala
implicit val optionShort: Schema[Option[Short]]

The schema of Option[Short], with a Some binding specialized for Short.

The schema of Option[Short], with a Some binding specialized for Short.

Attributes

Source
Schema.scala
implicit val optionUnit: Schema[Option[Unit]]

The schema of Option[Unit], with a Some binding specialized for Unit.

The schema of Option[Unit], with a Some binding specialized for Unit.

Attributes

Source
Schema.scala
implicit val period: Schema[Period]

The schema of java.time.Period.

The schema of java.time.Period.

Attributes

Source
Schema.scala
implicit def seq[A](implicit element: Schema[A]): Schema[Seq[A]]

The schema of Seq[A], built from the schema of its elements.

The schema of Seq[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit def set[A](implicit element: Schema[A]): Schema[Set[A]]

The schema of Set[A], built from the schema of its elements.

The schema of Set[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit val short: Schema[Short]

The schema of Short.

The schema of Short.

Attributes

Source
Schema.scala
implicit val string: Schema[String]

The schema of String.

The schema of String.

Attributes

Source
Schema.scala
implicit val unit: Schema[Unit]

The schema of Unit.

The schema of Unit.

Attributes

Source
Schema.scala
implicit val uuid: Schema[UUID]

The schema of java.util.UUID.

The schema of java.util.UUID.

Attributes

Source
Schema.scala
implicit def vector[A](implicit element: Schema[A]): Schema[Vector[A]]

The schema of Vector[A], built from the schema of its elements.

The schema of Vector[A], built from the schema of its elements.

Attributes

Source
Schema.scala
implicit val year: Schema[Year]

The schema of java.time.Year.

The schema of java.time.Year.

Attributes

Source
Schema.scala
implicit val yearMonth: Schema[YearMonth]

The schema of java.time.YearMonth.

The schema of java.time.YearMonth.

Attributes

Source
Schema.scala
implicit val zoneId: Schema[ZoneId]

The schema of java.time.ZoneId.

The schema of java.time.ZoneId.

Attributes

Source
Schema.scala
implicit val zoneOffset: Schema[ZoneOffset]

The schema of java.time.ZoneOffset.

The schema of java.time.ZoneOffset.

Attributes

Source
Schema.scala

The schema of java.time.ZonedDateTime.

The schema of java.time.ZonedDateTime.

Attributes

Source
Schema.scala

Inherited implicits

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val annotationSchema: Schema[Annotation]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val kindSchema: Schema[Kind]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val memberSchema: Schema[Member]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val ownerSchema: Schema[Owner]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val ownerSegmentSchema: Schema[Segment]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val paramSchema: Schema[Param]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val schemaAlignment: Schema[Alignment]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaBlock: Schema[Block]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaBlockQuote: Schema[BlockQuote]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaBulletList: Schema[BulletList]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaCode: Schema[Code]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaCodeBlock: Schema[CodeBlock]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaDoc: Schema[Doc]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaEmphasis: Schema[Emphasis]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaHardBreak: Schema[HardBreak.type]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaHeading: Schema[Heading]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaHeadingLevel: Schema[HeadingLevel]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaHtmlBlock: Schema[HtmlBlock]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaHtmlInline: Schema[HtmlInline]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaImage: Schema[Image]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInline: Schema[Inline]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineCode: Schema[Code]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineEmphasis: Schema[Emphasis]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineHardBreak: Schema[HardBreak.type]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineImage: Schema[Image]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineSoftBreak: Schema[SoftBreak.type]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineStrong: Schema[Strong]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaInlineText: Schema[Text]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaListItem: Schema[ListItem]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaOrderedList: Schema[OrderedList]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaParagraph: Schema[Paragraph]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaSoftBreak: Schema[SoftBreak.type]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaStrong: Schema[Strong]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaTable: Schema[Table]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaTableRow: Schema[TableRow]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaText: Schema[Text]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val schemaThematicBreak: Schema[ThematicBreak.type]

Attributes

Inherited from:
DocsSchemas (hidden)
Source
DocsSchemas.scala
implicit lazy val termPathSchema: Schema[TermPath]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val termPathSegmentSchema: Schema[Segment]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val tupleElementSchema: Schema[TupleElement]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val typeBoundsSchema: Schema[TypeBounds]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val typeDefKindSchema: Schema[TypeDefKind]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val typeIdSchema: Schema[TypeId[_ <: AnyKind]]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val typeParamSchema: Schema[TypeParam]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val typeReprSchema: Schema[TypeRepr]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala
implicit lazy val varianceSchema: Schema[Variance]

Attributes

Inherited from:
TypeIdSchemas
Source
TypeIdSchemas.scala