The root JSON schema of the entire form (N.B. rootSchema can also be a piece of the actual root
JSON schema, provided that has a JSON schema structure. Like for instance object
type, or oneOf
, and so on)
The form data associated with the schema
The list of options that can be selected from
Optional
selectedOption: number = undefinedThe index of the currently selected option, defaulted to undefined if not specified
formData
or the selectedOption
if no matchGenerated using TypeDoc
Determines which of the given
options
provided most closely matches theformData
. UsinggetFirstMatchingOption()
to match two schemas that differ only by the readOnly, default or const value of a field based on theformData
and returns 0 when there is no match. Rather than passing in all theoptions
at once to this utility, instead an array of valid option indexes is created by iterating over the list of options, callgetFirstMatchingOptions
with a list of one junk option and one good option, seeing if the good option is considered matched.Once the list of valid indexes is created, if there is only one valid index, just return it. Otherwise, if there are no valid indexes, then fill the valid indexes array with the indexes of all the options. Next, the index of the option with the highest score is determined by iterating over the list of valid options, calling
calculateIndexScore()
on each, comparing it against the current best score, and returning the index of the one that eventually has the best score.Adapted from https://github.com/rjsf-team/react-jsonschema-form/blob/b8f700a1cd2b9b8d7f67040e334836d236b325a4/packages/utils/src/schema/getClosestMatchingOption.ts#L136