๐Ÿ˜ธ kt-schema

JSON Schema DSL

Table of contents

For manual schema construction, use the kt-schema-json module. It provides type-safe Kotlin models compliant with the JSON Schema Draft 2020-12 specification and a DSL for building JSON Schema definitions programmatically, with full kotlinx-serialization support.

kotlin
dependencies {
    implementation("me.kpavlov.kt.schema:kt-schema-json:<version>")
}

Quick Example

kotlin
val schema = jsonSchema {
    property("id") {
        required = true
        string { format = "uuid" }
    }
    property("email") {
        required = true
        string { format = "email" }
    }
    property("age") {
        integer {
            minimum = 0.0
            maximum = 150.0
        }
    }
    // Polymorphic types with discriminators
    property("role") {
        oneOf {
            discriminator(propertyName = "type") {
                "admin" mappedTo "#/definitions/AdminRole"
                "user" mappedTo {
                    property("type") { string { constValue = "user" } }
                    property("permissions") { array { ofString() } }
                }
            }
        }
    }
}

Features

๐Ÿ“– For comprehensive documentation, see kt-schema-json/README.md covering:

See Also