skema

JsonSpec

@Serializable
sealed interface JsonSpec(source)

Built-in JSON-Schema-shaped config vocabulary. Use as the type parameter of Schema to get toJsonSchema without writing a mapper. For domain-specific configs, define your own sealed type and use the SchemaDef.toJsonSchema overload that takes a per-entry mapper lambda.

Inheritors

Types

Link copied to clipboard
@Serializable
@SerialName(value = "AllOf")
data class AllOf(val branches: List<JsonSpec>) : JsonSpec

Value must match all of the listed specs.

Link copied to clipboard
@Serializable
@SerialName(value = "Annotated")
data class Annotated(val inner: JsonSpec, val title: String? = null, val description: String? = null, val default: JsonElement? = null, val examples: List<JsonElement>? = null, val deprecated: Boolean? = null, val readOnly: Boolean? = null, val writeOnly: Boolean? = null, val comment: String? = null) : JsonSpec

Wraps another JsonSpec with JSON Schema annotations. Annotations decorate the inner spec without changing the values it accepts.

Link copied to clipboard
@Serializable
@SerialName(value = "AnyOf")
data class AnyOf(val branches: List<JsonSpec>) : JsonSpec

Value must match at least one of the listed specs.

Link copied to clipboard
@Serializable
@SerialName(value = "Array")
data class Array(val items: JsonSpec? = null, val prefixItems: List<JsonSpec>? = null, val minItems: Int? = null, val maxItems: Int? = null, val uniqueItems: Boolean? = null) : JsonSpec

Array of values. items constrains every element; prefixItems constrains the first N positionally (tuple-style); set both for a tuple with a trailing homogeneous tail.

Link copied to clipboard
@Serializable
@SerialName(value = "Bool")
data object Bool : JsonSpec

Boolean value. Maps to {"type":"boolean"}.

Link copied to clipboard
@Serializable
@SerialName(value = "Const")
data class Const(val value: JsonElement) : JsonSpec

Value constrained to a single constant. Maps to {"const": value}.

Link copied to clipboard
@Serializable
@SerialName(value = "Enum")
data class Enum(val values: List<String>) : JsonSpec

String value drawn from a fixed set. Maps to {"type":"string","enum":[...]}.

Link copied to clipboard
@Serializable
@SerialName(value = "IfThenElse")
data class IfThenElse(val condition: JsonSpec, val then: JsonSpec? = null, val otherwise: JsonSpec? = null) : JsonSpec

Conditional schema. If condition matches, then applies; otherwise otherwise applies. Either branch may be omitted.

Link copied to clipboard
@Serializable
@SerialName(value = "Int")
data class Int(val min: Int? = null, val max: Int? = null, val exclusiveMin: Int? = null, val exclusiveMax: Int? = null, val multipleOf: Int? = null) : JsonSpec

Integer value, optionally bounded. Maps to {"type":"integer"} plus minimum/maximum.

Link copied to clipboard
@Serializable
@SerialName(value = "Long")
data class Long(val min: Long? = null, val max: Long? = null, val exclusiveMin: Long? = null, val exclusiveMax: Long? = null, val multipleOf: Long? = null) : JsonSpec

64-bit integer value, optionally bounded. Maps to {"type":"integer"} plus minimum/maximum.

Link copied to clipboard
@Serializable
@SerialName(value = "Not")
data class Not(val spec: JsonSpec) : JsonSpec

Value must NOT match the given spec.

Link copied to clipboard
@Serializable
@SerialName(value = "Null")
data object Null : JsonSpec

Null value. Maps to {"type":"null"}. Useful as a branch in Nullable-style composition.

Link copied to clipboard
@Serializable
@SerialName(value = "Nullable")
data class Nullable(val inner: JsonSpec) : JsonSpec

Wraps a JsonSpec so the value may also be null. Renders as {"anyOf":[<inner>, {"type":"null"}]}. Equivalent to OneOf(inner, Null) but spells the intent out.

Link copied to clipboard
@Serializable
@SerialName(value = "Number")
data class Num(val min: Double? = null, val max: Double? = null, val exclusiveMin: Double? = null, val exclusiveMax: Double? = null, val multipleOf: Double? = null) : JsonSpec

Floating-point value, optionally bounded. Maps to {"type":"number"} plus minimum/maximum.

Link copied to clipboard
@Serializable
@SerialName(value = "Object")
data class Object(val properties: Map<String, JsonSpec> = emptyMap(), val required: List<String> = emptyList(), val additionalPropertiesAllowed: Boolean? = null, val additionalPropertiesSpec: JsonSpec? = null, val minProperties: Int? = null, val maxProperties: Int? = null) : JsonSpec

Object with named properties. additionalPropertiesAllowed gates extras; set additionalPropertiesSpec to constrain extras to a schema instead of a boolean. If both are set, the spec wins.

Link copied to clipboard
@Serializable
@SerialName(value = "OneOf")
data class OneOf(val branches: List<JsonSpec>) : JsonSpec

Value must match exactly one of the listed specs.

Link copied to clipboard
@Serializable
@SerialName(value = "Ref")
data class Ref(val pointer: String) : JsonSpec

Reference to a named spec defined elsewhere. Renders as {"$ref": pointer}. Pass pointer = "#/$defs/User" to point at a definition supplied via the defs parameter of SchemaDef.toJsonSchema; absolute URIs work too.

Link copied to clipboard
@Serializable
@SerialName(value = "String")
data class Str(val minLength: Int? = null, val maxLength: Int? = null, val pattern: String? = null, val format: String? = null) : JsonSpec

String value, optionally constrained by length and pattern.

Functions

Link copied to clipboard
fun JsonSpec.toJsonSchema(): JsonObject

JSON Schema fragment describing the value this primitive validates.