Skip to main content
Version: Current (v7.0.0-beta.3)

An option both lists hold is offered alone

Detect​

  • In your schema: a field with a oneOf or anyOf of its own beside an allOf entry, a then or an else whose list under the same keyword holds an option equal to one of the field's but for its annotations, without a customMergeAllOf.
  • In your schema: a field whose lists sit only in allOf entries, with an option two of them hold.
  • In your schema: options of the field's list and of an allOf entry's, then's or else's list that each hold an anyOf or oneOf sharing an option.
  • In your uiSchema or stored data: oneOf/anyOf entries past the field's own options, or a stored selectedOption index, for such a field.
  • In your code or tests: retrieveSchema() or getDefaultFormState() results for such a field, or assertions on the options its selector shows.
  • On the rendered page: the selector offers fewer options than before, and a repeated list offers its options once.

Change​

Before, retrieveSchema() merged that option with each option of the other list, and each of the other list's options with it, as 6.x did for an allOf: oneOf: [A, B] beside allOf: [{ oneOf: [A, B] }] gave [A, A×B, B×A, B].

Now, under oneOf, an option both lists hold pairs only with itself, since data meeting it and another option fails the list holding both. Under anyOf, an option built from every option another was built from, and more, is left out, since data meeting it meets that other too. With three or more lists this keeps each option the data needs from every list (#5953).

So a repeated list is offered as written, [A, B], a list narrowed to [A] offers [A], and an option index such as a stored selectedOption or a uiSchema.anyOf entry past the field's own options points at a different option or none. getDefaultFormState() starts a field with no value whose list an allOf entry narrows at the first option the entry leaves, where it started at the first of the field's own list, which the form may no longer offer. A list of constants narrowed to several starts unpicked, and one narrowed to a single constant fills it, as a list of one does, so an optional oneOf: [a, b] narrowed to [b] now starts at b. A list of object constants narrowed to one still starts empty.

A list an option of each list holds, such as an anyOf in each, is narrowed the same way inside the pair they build, so anyOf: [P, Q] and anyOf: [P, S] offer [P, Q×S] where they offered four options, and omitExtraData keeps only the keys of the one shown. Those options are built by a merge, as the outer pairs are, so a pick among them that ties with another where the data is matched again, as after reset() or setFieldValue(), stands only where it ranks as well, see getClosestMatchingOption(): with anyOf: [P, Q] and anyOf: [S, T], a pick of Q, S for data holding only S's key goes to P, S where Q requires a key (#5979).

A field whose lists sit only in allOf entries is narrowed the same way. It has no list of its own, so its uiSchema.oneOf/anyOf entries describe the options left by position and have to be rewritten for them.

const A: RJSFSchema = { title: 'A', properties: { a: { type: 'string' } } };
const B: RJSFSchema = { title: 'B', properties: { b: { type: 'string' } } };
const C: RJSFSchema = { title: 'C', properties: { c: { type: 'string' } } };
const schema: RJSFSchema = { type: 'object', anyOf: [A, B], allOf: [{ anyOf: [A, C] }] };
createSchemaUtils(context, schema).retrieveSchema(schema).anyOf.map((option) => Object.keys(option.properties));
// Before: [['a'], ['a', 'c'], ['b', 'a'], ['b', 'c']]. After: [['a'], ['b', 'c']]

To keep offering an option merged with another, give the merged option its own entry in one of the lists:

-const schema: RJSFSchema = { type: 'object', anyOf: [A, B], allOf: [{ anyOf: [A, C] }] };
+const schema: RJSFSchema = { type: 'object', anyOf: [A, B, { allOf: [A, C] }], allOf: [{ anyOf: [A, C] }] };

See oneOf, anyOf, and allOf for how merged options are built and labelled.

Verify​

  • The selector offers the options you expect, and each uiSchema.oneOf/anyOf entry and stored option index names the option you meant.
  • A field with no value opens on the option you expect, and a narrowed list of constants starts empty or filled as described above.

Also read: