julianpeeters / schemabuilder4cats   0.1.3

Apache License 2.0 GitHub

A referentially transparent FFI to `org.apache.avro.SchemaBuilder`

Scala versions: 3.x

schemabuilder4cats

  • Library for Scala 3 (JVM only)
  • Depends on Avro 1.11.3

Installation

Build schemas secure in the knowledge that we won't be causing side-effects.

Add the dependency
"com.julianpeeters" %% "schemabuilder4cats" % "0.1.3"

Usage

The SchemaBuilder API is modelled after Apache Avro Java 1.11.3 API. Please see the corresponding org.apache.avro.SchemaBuilder Javadoc for documentation.

Example:
import cats.effect.IO
import org.apache.avro.Schema
import schemabuilder4cats.SchemaBuilder

// define B as a contextual abstraction in order to import extension methods
given B: SchemaBuilder[IO] = SchemaBuilder[IO]
val record: IO[Schema] = B.record("myrecord").fields.endRecord
Result:
import cats.effect.unsafe.implicits.global

// example usage only, avoid unsafe methods in real code
record.unsafeRunSync().toString(true)
// res0: String = """{
//   "type" : "record",
//   "name" : "myrecord",
//   "fields" : [ ]
// }"""