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
- Self type
-
Schema.type
Members list
Type members
Inherited and Abstract types
The names of the product elements.
The name of the type.
Value members
Concrete methods
Returns the implicit schema of A, as in Schema[Book].
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
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
The schema of BigDecimal.
The schema of BigInt.
The schema of Boolean.
The schema of Byte.
The schema of Char.
The schema of Chunk[A], built from the schema of its elements.
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
The schema of java.util.Currency.
The schema of java.time.DayOfWeek.
The schema of Double.
The schema of java.time.Duration.
The schema of DynamicValue, which accepts any dynamic value.
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
The schema of Float.
The schema of IndexedSeq[A], built from the schema of its elements.
The schema of java.time.Instant.
The schema of Int.
The schema of List[A], built from the schema of its elements.
The schema of java.time.LocalDate.
The schema of java.time.LocalDateTime.
The schema of java.time.LocalTime.
The schema of Long.
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
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
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
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
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
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
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
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
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
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
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
The schema of java.time.Month.
The schema of java.time.MonthDay.
The schema of java.time.OffsetDateTime.
The schema of java.time.OffsetTime.
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
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
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
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
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
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
The schema of Option[Int], with a Some binding specialized for Int.
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
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
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
The schema of java.time.Period.
The schema of Seq[A], built from the schema of its elements.
The schema of Set[A], built from the schema of its elements.
The schema of Short.
The schema of String.
The schema of Unit.
The schema of java.util.UUID.
The schema of Vector[A], built from the schema of its elements.
The schema of java.time.Year.
The schema of java.time.YearMonth.
The schema of java.time.ZoneId.
The schema of java.time.ZoneOffset.
The schema of java.time.ZonedDateTime.
Inherited implicits
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- DocsSchemas (hidden)
- Source
- DocsSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala
Attributes
- Inherited from:
- TypeIdSchemas
- Source
- TypeIdSchemas.scala