oneOf

Creates a oneOf property definition.

Validates that the value matches exactly one of the provided schemas. Useful for polymorphic types with mutually exclusive alternatives.

Example - Simple oneOf

property("payment") {
oneOf {
obj {
property("type") {
required = true
string { constValue = "credit_card" }
}
property("cardNumber") {
required = true
string()
}
}
obj {
property("type") {
required = true
string { constValue = "paypal" }
}
property("email") {
required = true
string { format = "email" }
}
}
}
}

Example - oneOf with Discriminator

property("shape") {
oneOf {
description = "A geometric shape"
discriminator("type") {
mapping = mapOf(
"circle" to "#/definitions/Circle",
"rectangle" to "#/definitions/Rectangle"
)
}
reference("#/definitions/Circle")
reference("#/definitions/Rectangle")
}
}

Return

A configured OneOfPropertyDefinition

Parameters

block

Configuration for the oneOf property

See also