A non-object field's anyOf or oneOf option renders with its parent's keywords
Detect
- Your schema has a field that is not an object, such as a string or an array, with
anyOf/oneOfoptions and keywords beside them such asformat,enum,examples,readOnly,items,maxItemsorminimum. - Your schema has a
typelist namingobject, such as['object', 'string']or a nullable['object', 'null'], with an option of another type. - On the rendered page, such a field now renders a different widget, such as a date input or a multi-select.
Change
A field with anyOf/oneOf options is rendered entirely by its selected option, unless it is an object, whose own ObjectField renders its properties beside the option. A type list naming object counts as an object only while the option shown can hold one, so an option of another type, a null option included, renders the whole field wherever object sits in the list (#5725).
The option used to inherit only the field's required list and type (#5359). It now inherits every keyword of the field that describes its value. So this schema, which rendered "Unsupported field schema ... Missing items definition.", now renders a multi-select, and a format: 'date' string with options now renders a date input:
{
"type": "array",
"items": { "type": "string", "enum": ["a", "b"] },
"uniqueItems": true,
"oneOf": [{ "minItems": 1 }, { "maxItems": 1 }]
}
Where both the field and the option declare a keyword, the merge works like this:
- A bound both declare, such as
maxItems,maxLengthorminimum, keeps the stricter of the two: an option'smaxItems: 5beside the field'smaxItems: 3stops Add at three items, and switching to that option trims the array to three. - An option's
truesubschema, such asitems: true, leaves the field's subschema in place, a tuple included. A field'sfalsesubschema stays in place of the option's. - An option's
itemsschema beside the field's tuple applies to each of its positions, and to the items past it where the tuple declaresadditionalItems. A tuple declaring none stays at its length, and so does an option's tuple beside the field'sitemsschema. - An
enumthe option declares is its own list as it stands, since itsui:enumNamesare read by position against it. A value the field'senumdoesn't list stays, and validation rejects it. - Two
requiredlists ask for every name either does. - A
not, or a conditional (if,thenandelsetogether), that the option declares replaces the field's as a whole. - Any other keyword both declare, such as a
formator apattern, is the option's. - A subschema either declares through a
$ref, such asitems: { "$ref": "#/$defs/short" }, is left to the field'sallOfmerge, which meets the two once the$refis resolved.
The field's title, description, deprecated and default stay with the field. Its own template labels it whichever option is selected; see An anyOf or oneOf field is labelled once by its own template.
Remove a keyword from the field, or move it into the options, where you didn't mean every option to have it. Bounds use the draft-06 numeric form; see Draft-04 boolean exclusiveMinimum and exclusiveMaximum.
Verify
- Switching options checks the value against the option as it renders, inherited keywords included, so an array whose options only limit its length keeps its items where it used to be cleared.
- A string, number or boolean is kept by a switch to an option that holds it, and dropped otherwise, as An option switch keeps a scalar the new option holds describes.
- A tuple keeps its items, each sanitized against the schema the selected option declares at its position, unless the selected option changes the type of a prefix position to one that can't hold its item, which clears the array. An item past them is dropped.
- An array the selected option has a
constfor is replaced with thatconstwhen it doesn't equal it, and one an option'senumof whole arrays doesn't list is cleared, unless the option switched away from declared the sameconstorenum. - Where both options render the items alike, with the same uiSchema and a field per item, and the switch keeps the array's length, an item field's own errors stay with the item. An option that is a select over whole arrays, or one holding options of its own, drops them on a switch.
ui:requiredis checked against the option as it renders: aui:requiredfield within the field'sitemsis checked where an option'sitems: trueleaves them in place, and one the field'sfalsesubschema forbids is not.- Defaults are computed from the option as it renders. An option's
minItems: 1beside the field'sminItems: 2starts the form with two items, each holding the defaults of the field'sitems, whether the option is written in place or as a$ref, and a tuple's options add to the defaults of its positions. - An option written as a
$refis followed only to the schema it names, so anallOfwithin it is still left to theallOfdefaults behavior. One that inherits nothing from the field, such as the option of a typeless field, takes the field'sdefaultonly when there is no data. One that inherits something takes the field'sdefaultbeneath its data and its owndefault. - A non-object field declaring both
anyOfandoneOfrenders only theanyOfoption unless theanyOfis empty, so its defaults are that option's alone, where they used to include those of the selectedoneOfoption. An object field still adds both. - An object that names no
typebut haspropertiesnow passesobjecton to options that name no type either, so they render as a typed object's options do where they rendered "Unsupported field schema ... Unknown field type undefined."
Also read: