Given legacy Avro schemas, create Baleen data descriptions to do validation.
Create Baleen description files from Avro schemas
import com.shoprunner.baleen.avro.BaleenGenerator.encode
val parser = Schema.Parser()
val dogSchemaStr = """
|{
| "type": "record",
| "namespace": "com.shoprunner.data.dogs",
| "name": "Dog",
| "doc": "It's a dog. Ruff Ruff!",
| "fields": [
| { "name": "name", "type": "string", "doc": "The name of the dog" },
| { "name": "legs", "type": ["null", "long", "int"], "default": null, "doc": "The number of legs" }
| ]
|}
""".trimMargin()
val dogSchema = parser.parse(dogSchemaStr)
val sourceDir = encode(dogSchema).writeTo(File("src/main/kotlin"))
This produces working Kotlin Code
package com.shoprunner.data.dogs
import com.shoprunner.baleen.Baleen
import com.shoprunner.baleen.DataDescription
import com.shoprunner.baleen.types.IntType
import com.shoprunner.baleen.types.LongType
import com.shoprunner.baleen.types.StringType
import com.shoprunner.baleen.types.UnionType
import kotlin.jvm.JvmStatic
/**
* It's a dog. Ruff Ruff! */
object DogType {
@JvmStatic
val description: DataDescription =
Baleen.describe("Dog", "com.shoprunner.data.dogs", "It's a dog. Ruff Ruff!") {
p ->
p.attr(
name = "name",
type = StringType(),
markdownDescription = "The name of the dog",
required = true
)
p.attr(
name = "legs",
type = UnionType(LongType(), IntType()),
markdownDescription = "The number of legs",
required = false
)
}
}
import com.shoprunner.baleen.avro.AvroGenerator.encode
import com.shoprunner.baleen.avro.AvroGenerator.writeTo
val sourceDir = File("src/main/avro")
encode(DogType.description).writeTo(sourceDir)