DiscriminatorBuilder

Builder for Discriminator.

Configures a discriminator for efficient polymorphic type resolution. The discriminator identifies which schema applies based on a property value.

This class is part of the JSON Schema DSL and cannot be instantiated directly. Use within OneOfPropertyBuilder.discriminator context.

Example with references

oneOf {
discriminator("type") {
"dog" mappedTo "#/definitions/Dog"
"cat" mappedTo "#/definitions/Cat"
}
// References are added automatically
}

Example with inline schemas

oneOf {
discriminator("paymentType") {
"credit_card" mappedTo {
property("type") { string { constValue = "credit_card" } }
property("cardNumber") { string() }
}
"paypal" mappedTo {
property("type") { string { constValue = "paypal" } }
property("email") { string { format = "email" } }
}
}
}

See also

Functions

Link copied to clipboard
infix fun String.mappedTo(block: ObjectPropertyBuilder.() -> Unit)

Maps a discriminator value to an inline object schema, automatically adding it to the parent oneOf options.

infix fun String.mappedTo(ref: String)

Maps a discriminator value to a schema reference, automatically adding the reference to the parent oneOf options and the explicit mapping.