skema

Top-level

Types

Link copied to clipboard
@Serializable
sealed interface JsonSpec

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.

Link copied to clipboard
abstract class Schema<C : Any>

Builder base for any schema'd Eignex library. Subclasses expose library-specific declarators that call add (assignment form) or register (delegate form). definition returns the wire form.

Link copied to clipboard
@Serializable
data class SchemaDef<C>(val entries: Map<String, C>)

Pure-data, serializable form of a Schema. The default root field name is entries; for a different name or adjunct fields, define your own Serializable wrapper and override Schema.definition.

Link copied to clipboard
data class SchemaDiff<C>(val added: Map<String, C>, val removed: Map<String, C>, val changed: Map<String, Pair<C, C>>)

Per-entry difference between two schemas. Equal entries on both sides are omitted.

Properties

Link copied to clipboard
val SchemaJson: Json

Convenience Json instance pre-configured with schemaJsonConfig.

Link copied to clipboard
val schemaJsonConfig: JsonBuilder.() -> Unit

Recommended Json configuration for Eignex schema payloads. Apply to any Json builder (Json { schemaJsonConfig() }) for the standard $type discriminator with suppressed defaults.

Functions

Link copied to clipboard
fun <C> SchemaDef<C>.diff(other: SchemaDef<C>): SchemaDiff<C>

Computes the SchemaDiff from this schema to other.

Link copied to clipboard
fun <C> SchemaDef<C>.namespaced(prefix: String, separator: String = "."): SchemaDef<C>

Prefix every entry name (default separator .).

Link copied to clipboard
operator fun <C> SchemaDef<C>.plus(other: SchemaDef<C>): SchemaDef<C>

Combine two schemas into one; throws on any overlapping name.

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

JSON Schema fragment describing the value this primitive validates.

fun SchemaDef<JsonSpec>.toJsonSchema(defs: Map<String, JsonSpec> = emptyMap()): JsonObject

JSON Schema (draft 2020-12) for a schema whose entries are JsonSpecs. All entries are emitted as required; post-process the result if a different required-set is needed. Supply defs to populate the root $defs block; reference them with JsonSpec.Ref("#/${'$'}defs/<name>").

fun <C : Any> SchemaDef<C>.toJsonSchema(defs: Map<String, JsonSpec> = emptyMap(), map: (C) -> JsonObject): JsonObject

JSON Schema (draft 2020-12) for an arbitrary config vocabulary. Supply a mapper that turns each entry's config into a JSON Schema fragment for the value it validates. For mixed hierarchies, call JsonSpec.toJsonSchema inside the lambda for the JsonSpec branches. Supply defs to populate the root $defs block.