jsonSchema
DSL for building JSON Schema objects in a type-safe and readable way.
This is the main entry point for creating JSON Schema definitions using a Kotlin DSL. The DSL provides type-safe builders for all JSON Schema property types with automatic validation and conversion.
Basic Example
val schema = jsonSchema {
name = "UserEmail"
strict = false
schema {
property("email") {
required = true
string {
description = "Email address"
format = "email"
}
}
}
}Content copied to clipboard
Schema with Multiple Property Types
val schema = jsonSchema {
name = "Config"
schema {
property("enabled") {
boolean {
description = "Feature enabled"
default = true
}
}
property("count") {
integer {
description = "Item count"
default = 10
}
}
property("score") {
number {
description = "User score"
minimum = 0.0
maximum = 100.0
}
}
}
}Content copied to clipboard
Schema with Arrays
val schema = jsonSchema {
name = "Tags"
schema {
property("tags") {
array {
description = "List of tags"
minItems = 1
maxItems = 10
ofString()
}
}
}
}Content copied to clipboard
Schema with Nested Objects
val schema = jsonSchema {
name = "Metadata"
schema {
property("metadata") {
obj {
description = "User metadata"
property("createdAt") {
required = true
string {
format = "date-time"
}
}
}
}
}
}Content copied to clipboard
Return
A fully constructed JsonSchema instance
Parameters
block
Configuration block for the schema builder