A schema with both anyOf and oneOf reads anyOf first everywhere
Detect
- In your schema: a node with both
anyOfandoneOf. - In your tests or CSS: an option selector id ending in
__oneof_selecton such a node. - In your
uiSchema: option labels or per-option settings underoneOffor such a node. - On the rendered page: the error
schema cannot be inferred as a constantduring render.
Change
optionsList() and the option selector read anyOf before oneOf. isSelect(), sanitizeDataForNewSchema(), BooleanField, the LayoutGridField path (findFieldInSchema(), LayoutMultiSchemaField), the defaults getDefaultFormState() computes, the ui:required check, retrieveSchema()'s option resolution and getClosestMatchingOption()'s scoring of nested properties read oneOf first (#5309). They now all read anyOf first through the new getXxxOfKey() utility, and an empty anyOf: [] gives way to a non-empty oneOf.
As a result:
- A constant default comes from the
anyOfoptions on screen, and aui:requiredfield inside the renderedanyOfoption is reported. - The selector's
idsuffix is__anyof_select, where it used to be__oneof_selectwhenever aoneOfwas present. - Its options take their labels and per-option
uiSchemafromuiSchema.anyOf, where they came fromuiSchema.oneOf. - A schema with constant options under both keywords renders the
anyOfoptions. One whoseanyOfoptions aren't all constants renders thatanyOf's option selector, where it used to render a select of theoneOfconstants.
Give the two keywords the same options, or drop the redundant one:
{
"anyOf": [{ "const": "a" }, { "const": "b" }],
- "oneOf": [{ "const": "a" }, { "const": "b" }]
}
A schema with only one of the two keywords is unaffected.
Verify
- The node renders one list of options, its defaults and
ui:requiredchecks follow that list, and your selectors match__anyof_select.
Also read: