Reference Structured data
PlaySchema
Builds a Schema from a Play JSON Format, from the
anthropic4s-play-json module.
Reference#
PlaySchema.derived[A]#
def derived[A](implicit format: Format[A]): Schema[A]
The structure is derived from the type; reading and writing go through your Format.
Caveats
- Only the outermost type needs a schema: nested types only need their
Format.
Helpers#
def from[A](structure: Schema[A])(implicit format: Format[A]): Schema[A]
def enumFormat[A](values: (String, A)*): Format[A]
def decoder[A](implicit reads: Reads[A]): Decoder[A]
def encoder[A](implicit writes: Writes[A]): Encoder[A]
def toCirce(value: JsValue): CirceJson
def toPlay(value: CirceJson): JsValue
from: an existing structure with yourFormatas its codec.enumFormat: aFormatfor a fixed set of values, written as strings.decoder, encoder: circe codecs from Play'sReadsandWrites.toCirce, toPlay: JSON values from one library to the other.
PlaySchema.configuration#
val configuration: JsonConfiguration.Aux[Json.MacroOptions]
The Play JSON configuration that matches the derived schemas: a type discriminator with short class names, and None written as null.
Usage#
From a Format#
object Book {
implicit val config: JsonConfiguration = PlaySchema.configuration
implicit val format: OFormat[Book] = Json.format[Book]
implicit val schema: Schema[Book] = PlaySchema.derived[Book]
}
client.messages.parse[Book](request)
Using anthropic4s from Play shows it in a controller.
Every signature and example on this page is copied, character for character, from the public source of anthropic4s and its Scaladoc. The complete API, every type included, is in the Scaladoc of each module.