# JSON Schema DSL

For manual schema construction, use the [**kt-schema-json**](https://github.com/kpavlov/kt-schema/blob/main/kt-schema-json) module.
It provides type-safe Kotlin models compliant with
the [JSON Schema Draft 2020-12](https://json-schema.org/draft/2020-12/schema) 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

- ✅ Type-safe property definitions (string, number, integer, boolean, array, object, reference)
- ✅ **Polymorphism**: oneOf, anyOf, allOf with elegant discriminator support
- ✅ **Type-safe enums**: Native Kotlin types (`List<String>`, `List<Number>`, etc.) instead of `JsonElement`
- ✅ Constraints: required, nullable, enum, const, min/max, format validation
- ✅ Nested schemas and arrays of complex types
- ✅ Full kotlinx-serialization integration
- ✅ Kotlin Multiplatform support

**📖 For comprehensive documentation, see [kt-schema-json/README.md](https://github.com/kpavlov/kt-schema/blob/main/kt-schema-json/README.md)** covering:

- Complete DSL reference and type-safe enum API
- Polymorphism patterns (oneOf, anyOf, allOf) with discriminators
- Generic properties with heterogeneous enums
- Working with nested objects and arrays
- Serialization/deserialization examples
- Function calling schema for LLM APIs

## See Also

- [Generated Schemas](https://kpavlov.github.io/kt-schema/generated/index.md) — the same model, produced from your classes instead of by hand
- [Validation Constraints](https://kpavlov.github.io/kt-schema/constraints/index.md) — the keywords generators emit from annotations