Warn from SchemaField, for every type, when a non-empty anyOf hides a titled oneOf
Prerequisites
- I have read the documentation
What theme are you using?
core
Is your feature request related to a problem? Please describe.
Follow-up from #5364 (#5319), found in a review of 7f9c730ed.
getXxxOfKey() picks the one keyword whose options are rendered, and a non-empty anyOf wins over the oneOf. Every reader of the options goes through it (SchemaField's getSelectSchemaInfo(), optionsList(), sanitizing, defaults, the layout grid), so a oneOf beside a non-empty anyOf is never rendered, whatever the field's type. Its titles are dropped without a warning:
{
"type": "boolean",
"anyOf": [{ "type": "boolean" }],
"oneOf": [{ "const": true, "title": "On" }, { "const": false, "title": "Off" }]
}With { "ui:widget": "select" }, the select is built from the anyOf, so "On"/"Off" never appear, and nothing is logged. The same holds for a string or number field, and for an object whose oneOf would render an option selector.
#5364 warns about this only in BooleanField, and only when the schema also has an enum (the altKey === ANY_OF_KEY branch of its non-constant warning). Without an enum, or for any other type, it's silent.
Describe the solution you'd like
Warn once from SchemaField, which already calls getXxxOfKey() for every field:
In
SchemaFieldRender, aftergetSelectSchemaInfo(),logOnce()a warning naming the field (fieldLabelForLog()) when:- the keyword picked is
anyOf, schema.oneOfis a non-empty array, andhasOptionLabels(schema.oneOf, ONE_OF_KEY, uiSchema)is true, i.e. someoneOfoption has atitleor aui:titleinuiSchema.oneOf.
The message says the
oneOfisn't rendered because theanyOfis read first, and suggests moving the labels to theanyOfor merging the two lists.- the keyword picked is
Skip it when a
ui:fieldreplaces the field, since a custom field may read theoneOfitself (the same custom-field caveat as #5398).Remove the
altKey === ANY_OF_KEYbranch fromBooleanField, so the booleanenumcase logs one warning, not two.
Tests:
SchemaFieldwarns exactly once for a boolean without anenum(the schema above), a string, a number, and an object option selector.- It doesn't warn when the
anyOfis empty (theoneOfis then rendered), when theoneOfhas no titles, when there's only aoneOf, or when aui:fieldis set. BooleanField's existingenum+anyOf+ titledoneOftest expects theSchemaFieldwarning, still exactly once.
Reword the #5319 core entry in CHANGELOG-v7.md to say the warning covers any field.
This sits alongside #5398, which moves BooleanField's other two warnings into SchemaField; the two could land together.
Describe alternatives you've considered
- Warn whenever a non-empty
oneOfis hidden, titled or not. That also flags aoneOfwritten only for validation beside ananyOf, where nothing the author meant to show is lost. - Render both keywords, as separate selectors. That changes the long-standing
anyOf-first precedence that every reader of the options relies on. - Leave the warning boolean-and-
enum-only, as #5364 does.
Generated with Claude Code
Source: rjsf-team/react-jsonschema-form