• Recursive function that calculates the score of a formData against the given schema. The computation is fairly simple. Initially the total score is 0. When schema.properties object exists, then all the key/value pairs within the object are processed as follows after obtaining the formValue from formData using the key:

    • If the value contains a oneOf and there is a formValue, then score based on the index returned from calling getClosestMatchingOption() of that oneOf.
    • If the type of the value is 'object', calculateIndexScore() is called recursively with the formValue and the value itself as the sub-schema, and the score is added to the total.
    • If the type of the value matches the guessed-type of the formValue, the score is incremented by 1, UNLESS the value has a default or const. In those case, if the default or const and the formValue match, the score is incremented by another 1 otherwise it is decremented by 1.

    Adapted from https://github.com/rjsf-team/react-jsonschema-form/blob/b8f700a1cd2b9b8d7f67040e334836d236b325a4/packages/utils/src/schema/getClosestMatchingOption.ts#L50

    Parameters

    • rootSchema: JsonSchema

      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)

    • Optional schema: any

      The schema for which the score is being calculated

    • formData: any = {}

      The form data associated with the schema, used to calculate the score

    Returns number

    • The score a schema against the formData

Generated using TypeDoc